From 8d4155530f85a38980acdd6c5716e6f684c4d79f Mon Sep 17 00:00:00 2001 From: Catalin Marinas Date: Thu, 7 Dec 2006 22:02:41 +0000 Subject: [PATCH] Fix a merge case with files added in both heads but different 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 --- stgit/git.py | 9 +++++++++ stgit/gitmergeonefile.py | 8 +++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/stgit/git.py b/stgit/git.py index 13f7b87..21d74dd 100644 --- a/stgit/git.py +++ b/stgit/git.py @@ -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], diff --git a/stgit/gitmergeonefile.py b/stgit/gitmergeonefile.py index b35880e..a8dc2a8 100644 --- a/stgit/gitmergeonefile.py +++ b/stgit/gitmergeonefile.py @@ -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 -- 2.11.0