diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -890,6 +890,9 @@ def iterhunks(ui, fp, sourcefile=None): context = None lr = linereader(fp) dopatch = True + # gitworkdone is True if a git operation (copy, rename, ...) was + # performed already for the current file. Useful when the file + # section may have no hunk. gitworkdone = False while True: @@ -938,8 +941,8 @@ def iterhunks(ui, fp, sourcefile=None): changed[gp.path] = (gp.op, gp) # else error? # copy/rename + modify should modify target, not source - if changed.get(bfile[2:], (None, None))[0] in ('COPY', - 'RENAME'): + gitop = changed.get(bfile[2:], (None, None))[0] + if gitop in ('COPY', 'DELETE', 'RENAME'): afile = bfile gitworkdone = True newfile = True diff --git a/tests/test-import b/tests/test-import --- a/tests/test-import +++ b/tests/test-import @@ -207,3 +207,21 @@ do done cd .. +# Test importing a patch ending with a binary file removal +echo % test trailing binary removal +hg init binaryremoval +cd binaryremoval +echo a > a +python -c "file('b', 'wb').write('a\x00b')" +hg ci -Am addall +hg rm a +hg rm b +hg st +hg ci -m remove +hg export --git . > remove.diff +cat remove.diff | grep git +hg up -C 0 +hg import remove.diff +hg manifest +cd .. + diff --git a/tests/test-import.out b/tests/test-import.out --- a/tests/test-import.out +++ b/tests/test-import.out @@ -223,3 +223,12 @@ c % c2 file c % d file +% test trailing binary removal +adding a +adding b +R a +R b +diff --git a/a b/a +diff --git a/b b/b +2 files updated, 0 files merged, 0 files removed, 0 files unresolved +applying remove.diff