Fix a merge case with files added in both heads but different
authorCatalin Marinas <catalin.marinas@gmail.com>
Thu, 7 Dec 2006 22:02:41 +0000 (22:02 +0000)
committerCatalin Marinas <catalin.marinas@gmail.com>
Thu, 7 Dec 2006 22:02:41 +0000 (22:02 +0000)
Since using git-merge-recursive instead of git-read-tree, the local
file is removed if it was added in both heads but different. We now
re-generated it in gitmergeonefile.merge. The patch also cleans the
working directory of extra files generated by git-merge-recursive
since our own merge re-generates them with nicer naming.

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
stgit/git.py
stgit/gitmergeonefile.py

index 13f7b87..21d74dd 100644 (file)
@@ -629,6 +629,15 @@ def merge(base, head1, head2):
     # merge the unmerged files
     errors = False
     for path in files:
+        # remove additional files that might be generated for some
+        # newer versions of GIT
+        for suffix in [base, head1, head2]:
+            if not suffix:
+                continue
+            fname = path + '~' + suffix
+            if os.path.exists(fname):
+                os.remove(fname)
+
         stages = files[path]
         if gitmergeonefile.merge(stages['1'][1], stages['2'][1],
                                  stages['3'][1], path, stages['1'][0],
index b35880e..a8dc2a8 100644 (file)
@@ -75,6 +75,13 @@ def __checkout_files(orig_hash, file1_hash, file2_hash,
         os.chmod(tmp, int(file2_mode, 8))
         os.renames(tmp, src2)
 
+    if file1_hash and not os.path.exists(path):
+        # the current file might be removed by GIT when it is a new
+        # file added in both branches. Just re-generate it
+        tmp = __output('git-unpack-file %s' % file1_hash)
+        os.chmod(tmp, int(file1_mode, 8))
+        os.renames(tmp, path)
+
 def __remove_files(orig_hash, file1_hash, file2_hash):
     """Remove any temporary files
     """
@@ -84,7 +91,6 @@ def __remove_files(orig_hash, file1_hash, file2_hash):
         os.remove(src1)
     if file2_hash:
         os.remove(src2)
-    pass
 
 def __conflict(path):
     """Write the conflict file for the 'path' variable and exit