# HG changeset patch # User Alexis S. L. Carvalho # Date 1191695415 10800 # Node ID 477136fa65710c6ea2adb625785ee388b2a7ed4f # Parent ad0b580cad35f682d5a7c20191f24f214efcfd02 Always copy the necessary files before applying a git patch This patch removes the "copymod" attribute from the gitpatch class. AFAICS, that attribute was only used to delay the copying of renamed/copied files if there are no other changes to the target, but in this case, if there are changes to the source, we'll end up copying the wrong version. This should fix issue762. diff -r ad0b580cad35 -r 477136fa6571 mercurial/patch.py --- a/mercurial/patch.py Sat Oct 06 15:30:15 2007 -0300 +++ b/mercurial/patch.py Sat Oct 06 15:30:15 2007 -0300 @@ -151,7 +151,6 @@ self.oldpath = None self.mode = None self.op = 'MODIFY' - self.copymod = False self.lineno = 0 self.binary = False @@ -182,7 +181,6 @@ elif gp: if line.startswith('--- '): if gp.op in ('COPY', 'RENAME'): - gp.copymod = True dopatch |= GP_FILTER gitpatches.append(gp) gp = None @@ -858,7 +856,7 @@ (dopatch, gitpatches) = readgitpatch(fp, firstline) for gp in gitpatches: - if gp.copymod: + if gp.op in ('COPY', 'RENAME'): copyfile(gp.oldpath, gp.path, basedir=cwd) fp.seek(pos) @@ -1030,15 +1028,13 @@ for f in patches: ctype, gp = patches[f] if ctype == 'RENAME': - copies.append((gp.oldpath, gp.path, gp.copymod)) + copies.append((gp.oldpath, gp.path)) removes[gp.oldpath] = 1 elif ctype == 'COPY': - copies.append((gp.oldpath, gp.path, gp.copymod)) + copies.append((gp.oldpath, gp.path)) elif ctype == 'DELETE': removes[gp.path] = 1 - for src, dst, after in copies: - if not after: - copyfile(src, dst, repo.root) + for src, dst in copies: repo.copy(src, dst) removes = removes.keys() if removes: diff -r ad0b580cad35 -r 477136fa6571 tests/test-git-import --- a/tests/test-git-import Sat Oct 06 15:30:15 2007 -0300 +++ b/tests/test-git-import Sat Oct 06 15:30:15 2007 -0300 @@ -198,3 +198,19 @@ EOF cat "foo bar" +echo % copy then modify the original file +hg import -m copy-mod-orig - <