chiark / gitweb /
Failed recursive merging can silently lose date in StGIT stable
authorCatalin Marinas <catalin.marinas@gmail.com>
Tue, 17 Apr 2007 16:29:32 +0000 (17:29 +0100)
committerCatalin Marinas <catalin.marinas@gmail.com>
Tue, 17 Apr 2007 23:58:36 +0000 (00:58 +0100)
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>
stgit/git.py
stgit/stack.py

index 46ba5c8614e892e44ede8816f8d19fb76fe6baef..81f6501788a4ed71b911841845192e6ff2fc6e29 100644 (file)
@@ -606,13 +606,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
@@ -640,6 +642,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:
index 0f5d868d07e0b5b0d78901a52428d300644a4e1a..b21cc30899265fca7c7e28e59fff0ebede95ff5f 100644 (file)
@@ -1030,7 +1030,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)