From: Catalin Marinas Date: Tue, 17 Apr 2007 16:29:32 +0000 (+0100) Subject: Failed recursive merging can silently lose date in StGIT X-Git-Tag: v0.13~98 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/stgit/commitdiff_plain/6aff55e93e9814621dd7b8623e18036b540bda1a Failed recursive merging can silently lose date in StGIT 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 --- diff --git a/stgit/git.py b/stgit/git.py index f6d6b43..d7eb48e 100644 --- a/stgit/git.py +++ b/stgit/git.py @@ -672,13 +672,15 @@ def merge(base, head1, head2, recursive = False): """ refresh_index() + err_output = None 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: + except GitException, ex: + err_output = str(ex) pass else: # the fast case where we don't track renames (used when the @@ -706,6 +708,11 @@ def merge(base, head1, head2, recursive = False): 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: diff --git a/stgit/stack.py b/stgit/stack.py index a726cb5..b0a01dd 100644 --- a/stgit/stack.py +++ b/stgit/stack.py @@ -1046,7 +1046,8 @@ class Series(StgitObject): 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)