Class: Braid::Operations::Git
- Inherits:
-
Proxy
- Object
- Proxy
- Braid::Operations::Git
show all
- Defined in:
- lib/braid/operations.rb
Instance Method Summary
collapse
Methods inherited from Proxy
command, #require_version, #require_version!, verbose, #version
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Braid::Operations::Proxy
Instance Method Details
#apply(diff, *args) ⇒ Object
239
240
241
242
243
244
245
246
247
248
249
|
# File 'lib/braid/operations.rb', line 239
def apply(diff, *args)
err = nil
status = Open4.popen4("git apply --index --whitespace=nowarn #{args.join(' ')} -") do |pid, stdin, stdout, stderr|
stdin.puts(diff)
stdin.close
err = stderr.read
end.exitstatus
raise ShellExecutionError, err unless status == 0
true
end
|
#branch ⇒ Object
234
235
236
237
|
# File 'lib/braid/operations.rb', line 234
def branch
status, out, err = exec!("git branch | grep '*'")
out[2..-1]
end
|
#checkout(treeish) ⇒ Object
149
150
151
152
153
154
|
# File 'lib/braid/operations.rb', line 149
def checkout(treeish)
msg "Checking out '#{treeish}'."
invoke(:checkout, treeish)
true
end
|
#commit(message, *args) ⇒ Object
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/braid/operations.rb', line 130
def commit(message, *args)
status, out, err = exec("git commit -m #{message.inspect} --no-verify #{args.join(' ')}")
if status == 0
true
elsif out.match(/nothing.* to commit/)
false
else
raise ShellExecutionError, err
end
end
|
#diff_tree(src_tree, dst_tree, prefix = nil) ⇒ Object
214
215
216
217
218
219
|
# File 'lib/braid/operations.rb', line 214
def diff_tree(src_tree, dst_tree, prefix = nil)
cmd = "git diff-tree -p --binary #{src_tree} #{dst_tree}"
cmd << " --src-prefix=a/#{prefix}/ --dst-prefix=b/#{prefix}/" if prefix
status, out, err = exec!(cmd)
out
end
|
#ensure_clean! ⇒ Object
226
227
228
|
# File 'lib/braid/operations.rb', line 226
def ensure_clean!
status_clean? || raise(LocalChangesPresent)
end
|
#fetch(remote) ⇒ Object
142
143
144
145
146
147
|
# File 'lib/braid/operations.rb', line 142
def fetch(remote)
system("git fetch -n #{remote} 2>&1 >/dev/null")
raise ShellExecutionError, "could not fetch" unless $? == 0
true
end
|
#head ⇒ Object
230
231
232
|
# File 'lib/braid/operations.rb', line 230
def head
rev_parse("HEAD")
end
|
#merge_base(target, source) ⇒ Object
Returns the base commit or nil.
157
158
159
160
161
|
# File 'lib/braid/operations.rb', line 157
def merge_base(target, source)
invoke(:merge_base, target, source)
rescue ShellExecutionError
nil
end
|
#merge_ours(opt) ⇒ Object
187
188
189
190
|
# File 'lib/braid/operations.rb', line 187
def merge_ours(opt)
invoke(:merge, "-s ours --no-commit", opt)
true
end
|
#merge_subtree(opt) ⇒ Object
193
194
195
196
197
|
# File 'lib/braid/operations.rb', line 193
def merge_subtree(opt)
invoke(:merge, "-s subtree --no-commit --no-ff", opt)
true
end
|
#read_tree(treeish, prefix) ⇒ Object
199
200
201
202
|
# File 'lib/braid/operations.rb', line 199
def read_tree(treeish, prefix)
invoke(:read_tree, "--prefix=#{prefix}/ -u", treeish)
true
end
|
#remote_add(remote, path, branch) ⇒ Object
170
171
172
173
|
# File 'lib/braid/operations.rb', line 170
def remote_add(remote, path, branch)
invoke(:remote, "add", "-t #{branch} -m #{branch}", remote, path)
true
end
|
#remote_exists?(remote) ⇒ Boolean
Checks git and svn remotes.
176
177
178
179
|
# File 'lib/braid/operations.rb', line 176
def remote_exists?(remote)
!!File.readlines(".git/config").find { |line| line =~ /^\[(svn-)?remote "#{Regexp.escape(remote)}"\]/ }
end
|
#reset_hard(target) ⇒ Object
181
182
183
184
|
# File 'lib/braid/operations.rb', line 181
def reset_hard(target)
invoke(:reset, "--hard", target)
true
end
|
#rev_parse(opt) ⇒ Object
163
164
165
166
167
|
# File 'lib/braid/operations.rb', line 163
def rev_parse(opt)
invoke(:rev_parse, opt)
rescue ShellExecutionError
raise UnknownRevision, opt
end
|
#rm_r(path) ⇒ Object
204
205
206
207
|
# File 'lib/braid/operations.rb', line 204
def rm_r(path)
invoke(:rm, "-r", path)
true
end
|
#status_clean? ⇒ Boolean
221
222
223
224
|
# File 'lib/braid/operations.rb', line 221
def status_clean?
status, out, err = exec("git status")
!out.split("\n").grep(/nothing to commit/).empty?
end
|
#tree_hash(path, treeish = "HEAD") ⇒ Object
209
210
211
212
|
# File 'lib/braid/operations.rb', line 209
def tree_hash(path, treeish = "HEAD")
out = invoke(:ls_tree, treeish, "-d", path)
out.split[2]
end
|