lib/braid/operations.rb in braid-1.0.5 vs lib/braid/operations.rb in braid-1.0.6
- old
+ new
@@ -6,12 +6,15 @@
USE_OPEN3 = defined?(JRUBY_VERSION) || Gem.win_platform?
require USE_OPEN3 ? 'open3' : 'open4'
module Operations
class ShellExecutionError < BraidError
- def initialize(err = nil)
+ attr_reader :err, :out
+
+ def initialize(err = nil, out = nil)
@err = err
+ @out = out
end
def message
@err.to_s.split("\n").first
end
@@ -36,10 +39,16 @@
def message
'local changes are present'
end
end
class MergeError < BraidError
+ attr_reader :conflicts_text
+
+ def initialize(conflicts_text)
+ @conflicts_text = conflicts_text
+ end
+
def message
'could not merge'
end
end
@@ -132,11 +141,11 @@
ENV['LANG'] = previous_lang
end
def exec!(cmd)
status, out, err = exec(cmd)
- raise ShellExecutionError, err unless status == 0
+ raise ShellExecutionError.new(err, out) unless status == 0
[status, out, err]
end
def sh(cmd, message = nil)
message ||= 'could not fetch' if cmd =~ /fetch/
@@ -240,11 +249,12 @@
def merge_subtree(opt)
# TODO which options are needed?
invoke(:merge, '-s subtree --no-commit --no-ff', opt)
true
rescue ShellExecutionError
- raise MergeError
+ # TODO: Figure out how to pass along conflict messages.
+ raise MergeError, ''
end
# Merge three trees (local_treeish should match the current state of the
# index) and update the index and working tree.
#
@@ -254,11 +264,12 @@
# the trees matter. But for some reason, Git's smartest tree merge
# algorithm is only available via the "recursive" strategy.
def merge_trees(base_treeish, local_treeish, remote_treeish)
invoke(:merge_recursive, base_treeish, "-- #{local_treeish} #{remote_treeish}")
true
- rescue ShellExecutionError
- raise MergeError
+ rescue ShellExecutionError => error
+ # "CONFLICT" messages go to stdout.
+ raise MergeError, error.out
end
def read_ls_files(prefix)
invoke('ls-files', prefix)
end