Class: Braid::Operations::Git
- Inherits:
-
Proxy
- Object
- Proxy
- Braid::Operations::Git
show all
- Defined in:
- lib/braid/operations.rb
Instance Method Summary
collapse
-
#apply(diff, *args) ⇒ Object
-
#branch ⇒ Object
-
#checkout(treeish) ⇒ Object
-
#clone(*args) ⇒ Object
-
#commit(message, *args) ⇒ Object
-
#diff_tree(src_tree, dst_tree, prefix = nil) ⇒ Object
-
#ensure_clean! ⇒ Object
-
#fetch(remote = nil, *args) ⇒ Object
-
#head ⇒ Object
-
#merge_base(target, source) ⇒ Object
Returns the base commit or nil.
-
#merge_ours(opt) ⇒ Object
-
#merge_recursive(base_hash, local_hash, remote_hash) ⇒ Object
-
#merge_subtree(opt) ⇒ Object
-
#read_ls_files(prefix) ⇒ Object
-
#read_tree_prefix(treeish, prefix) ⇒ Object
-
#remote_add(remote, path, branch) ⇒ Object
-
#remote_rm(remote) ⇒ Object
-
#remote_url(remote) ⇒ Object
-
#reset_hard(target) ⇒ Object
-
#rev_parse(opt) ⇒ Object
-
#rm_r(path) ⇒ Object
-
#status_clean? ⇒ Boolean
-
#tree_hash(path, treeish = "HEAD") ⇒ Object
Methods inherited from Proxy
command, #require_version, #require_version!, #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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
|
# File 'lib/braid/operations.rb', line 299
def apply(diff, *args)
status, err = nil, nil
command = "git apply --index --whitespace=nowarn #{args.join(' ')} -"
if USE_OPEN3
Open3.popen3(command) do |stdin, stdout, stderr, wait_thread|
stdin.puts(diff)
stdin.close
err = stderr.read
status = wait_thread.value if wait_thread end
status = $?.exitstatus if status.nil?
else
status = Open4.popen4(command) do |pid, stdin, stdout, stderr|
stdin.puts(diff)
stdin.close
err = stderr.read
end.exitstatus
end
raise ShellExecutionError, err unless status == 0
true
end
|
#branch ⇒ Object
294
295
296
297
|
# File 'lib/braid/operations.rb', line 294
def branch
status, out, err = exec!("git branch | grep '*'")
out[2..-1]
end
|
#checkout(treeish) ⇒ Object
191
192
193
194
|
# File 'lib/braid/operations.rb', line 191
def checkout(treeish)
invoke(:checkout, treeish)
true
end
|
#clone(*args) ⇒ Object
326
327
328
329
|
# File 'lib/braid/operations.rb', line 326
def clone(*args)
invoke(:clone, *args)
end
|
#commit(message, *args) ⇒ Object
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
|
# File 'lib/braid/operations.rb', line 163
def commit(message, *args)
cmd = "git commit --no-verify"
if message message_file = Tempfile.new("braid_commit")
message_file.print("Braid: #{message}")
message_file.flush
message_file.close
cmd << " -F #{message_file.path}"
end
cmd << " #{args.join(' ')}" unless args.empty?
status, out, err = exec(cmd)
message_file.unlink if message_file
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
274
275
276
277
278
279
|
# File 'lib/braid/operations.rb', line 274
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
286
287
288
|
# File 'lib/braid/operations.rb', line 286
def ensure_clean!
status_clean? || raise(LocalChangesPresent)
end
|
#fetch(remote = nil, *args) ⇒ Object
185
186
187
188
189
|
# File 'lib/braid/operations.rb', line 185
def fetch(remote = nil, *args)
args.unshift "-n #{remote}" if remote
sh("git fetch #{args.join(' ')} 2>&1 > #{Gem.win_platform? ? 'nul' : '/dev/null'}")
end
|
#head ⇒ Object
290
291
292
|
# File 'lib/braid/operations.rb', line 290
def head
rev_parse("HEAD")
end
|
#merge_base(target, source) ⇒ Object
Returns the base commit or nil.
197
198
199
200
201
|
# File 'lib/braid/operations.rb', line 197
def merge_base(target, source)
invoke(:merge_base, target, source)
rescue ShellExecutionError
nil
end
|
#merge_ours(opt) ⇒ Object
234
235
236
237
|
# File 'lib/braid/operations.rb', line 234
def merge_ours(opt)
invoke(:merge, "-s ours --no-commit", opt)
true
end
|
#merge_recursive(base_hash, local_hash, remote_hash) ⇒ Object
248
249
250
251
252
253
|
# File 'lib/braid/operations.rb', line 248
def merge_recursive(base_hash, local_hash, remote_hash)
invoke(:merge_recursive, base_hash, "-- #{local_hash} #{remote_hash}")
true
rescue ShellExecutionError
raise MergeError
end
|
#merge_subtree(opt) ⇒ Object
240
241
242
243
244
245
246
|
# File 'lib/braid/operations.rb', line 240
def merge_subtree(opt)
invoke(:merge, "-s subtree --no-commit --no-ff", opt)
true
rescue ShellExecutionError
raise MergeError
end
|
#read_ls_files(prefix) ⇒ Object
255
256
257
|
# File 'lib/braid/operations.rb', line 255
def read_ls_files(prefix)
invoke('ls-files', prefix)
end
|
#read_tree_prefix(treeish, prefix) ⇒ Object
259
260
261
262
|
# File 'lib/braid/operations.rb', line 259
def read_tree_prefix(treeish, prefix)
invoke(:read_tree, "--prefix=#{prefix}/ -u", treeish)
true
end
|
#remote_add(remote, path, branch) ⇒ Object
210
211
212
213
|
# File 'lib/braid/operations.rb', line 210
def remote_add(remote, path, branch)
invoke(:remote, "add", "-t #{branch} -m #{branch}", remote, path)
true
end
|
#remote_rm(remote) ⇒ Object
215
216
217
218
|
# File 'lib/braid/operations.rb', line 215
def remote_rm(remote)
invoke(:remote, "rm", remote)
true
end
|
#remote_url(remote) ⇒ Object
221
222
223
224
225
226
|
# File 'lib/braid/operations.rb', line 221
def remote_url(remote)
key = "remote.#{remote}.url"
invoke(:config, key)
rescue ShellExecutionError
nil
end
|
#reset_hard(target) ⇒ Object
228
229
230
231
|
# File 'lib/braid/operations.rb', line 228
def reset_hard(target)
invoke(:reset, "--hard", target)
true
end
|
#rm_r(path) ⇒ Object
264
265
266
267
|
# File 'lib/braid/operations.rb', line 264
def rm_r(path)
invoke(:rm, "-r", path)
true
end
|
#status_clean? ⇒ Boolean
281
282
283
284
|
# File 'lib/braid/operations.rb', line 281
def status_clean?
status, out, err = exec("git status")
!out.split("\n").grep(/nothing to commit/).empty?
end
|
#tree_hash(path, treeish = "HEAD") ⇒ Object
269
270
271
272
|
# File 'lib/braid/operations.rb', line 269
def tree_hash(path, treeish = "HEAD")
out = invoke(:ls_tree, treeish, "-d", path)
out.split[2]
end
|