The logic in git.merge(recursive = True) is that if
git-merge-recursive fails, deal with the unmerged entries via diff3
and interactive merge (if 'autoimerge' is set to 'yes' in
config). There is a situation, however, when git-merge-recursive fails
because of an untracked file that would be overwritten by the
merge. In this case, git-merge-recursive aborts the operation but
without any unmerged entries in the index. StGIT considers that the
merge lead to an empty patch without reporting any error.
This commit makes it a bit safer by detecting whether there are
unmerged index entries and, if not, further raises an error informing
the user of the problem. The patch is still pushed as empty but the
user is informed of the failure and the possibility of running 'push
--undo'.
A better solution, but which require a bit more work, is to
distinguish between the merge failures and, in this specific case,
abort the push completely and revert the patch to its original state
(and popped from the stack).
Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
if recursive:
# this operation tracks renames but it is slower (used in
# general when pushing or picking patches)
try:
# use _output() to mask the verbose prints of the tool
_output('git-merge-recursive %s -- %s %s' % (base, head1, head2))
if recursive:
# this operation tracks renames but it is slower (used in
# general when pushing or picking patches)
try:
# use _output() to mask the verbose prints of the tool
_output('git-merge-recursive %s -- %s %s' % (base, head1, head2))
+ except GitException, ex:
+ err_output = str(ex)
pass
else:
# the fast case where we don't track renames (used when the
pass
else:
# the fast case where we don't track renames (used when the
files[path][stage] = (mode, hash)
files[path][stage] = (mode, hash)
+ if err_output and not files:
+ # if no unmerged files, there was probably a different type of
+ # error and we have to abort the merge
+ raise GitException, err_output
+
# merge the unmerged files
errors = False
for path in files:
# merge the unmerged files
errors = False
for path in files:
except git.GitException, ex:
print >> sys.stderr, \
'The merge failed during "push". ' \
except git.GitException, ex:
print >> sys.stderr, \
'The merge failed during "push". ' \
- 'Use "refresh" after fixing the conflicts'
+ 'Use "refresh" after fixing the conflicts or ' \
+ 'revert the operation with "push --undo".'
append_string(self.__applied_file, name)
append_string(self.__applied_file, name)