Patchwork D5243: resolve: fix mark-check when a file was deleted on one side (issue6020)

login
register
mail settings
Submitter phabricator
Date Jan. 16, 2019, 8:50 p.m.
Message ID <3a98760afd8493e874c688374a586436@localhost.localdomain>
Download mbox | patch
Permalink /patch/37839/
State Not Applicable
Headers show

Comments

phabricator - Jan. 16, 2019, 8:50 p.m.
spectral updated this revision to Diff 13298.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D5243?vs=12476&id=13298

REVISION DETAIL
  https://phab.mercurial-scm.org/D5243

AFFECTED FILES
  mercurial/commands.py
  tests/test-resolve.t

CHANGE DETAILS




To: spectral, #hg-reviewers
Cc: yuja, mercurial-devel
Yuya Nishihara - Jan. 17, 2019, 12:50 p.m.
Queued, thanks.

Replaced all `[[ -f ]]` with `[ -f ]`. ``[[]]`` requires Bash.
phabricator - Jan. 17, 2019, 1:17 p.m.
yuja added a comment.


  Queued, thanks.
  
  Replaced all `[[ -f ]]` with `[ -f ]`. ``[[]]`` requires Bash.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D5243

To: spectral, #hg-reviewers
Cc: yuja, mercurial-devel

Patch

diff --git a/tests/test-resolve.t b/tests/test-resolve.t
--- a/tests/test-resolve.t
+++ b/tests/test-resolve.t
@@ -629,3 +629,169 @@ 
 
 Done with commands.resolve.confirm tests:
   $ cd ..
+
+Test that commands.resolve.mark-check works even if there are deleted files:
+  $ hg init resolve-deleted
+  $ cd resolve-deleted
+  $ echo r0 > file1
+  $ hg ci -qAm r0
+  $ echo r1 > file1
+  $ hg ci -qm r1
+  $ hg co -qr 0
+  $ hg rm file1
+  $ hg ci -qm "r2 (delete file1)"
+
+(At this point we have r0 creating file1, and sibling commits r1 and r2, which
+ modify and delete file1, respectively)
+
+  $ hg merge -r 1
+  file 'file1' was deleted in local [working copy] but was modified in other [merge rev].
+  What do you want to do?
+  use (c)hanged version, leave (d)eleted, or leave (u)nresolved? u
+  0 files updated, 0 files merged, 0 files removed, 1 files unresolved
+  use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
+  [1]
+  $ hg resolve --list
+  U file1
+Because we left it as 'unresolved' the file should still exist.
+  $ [[ -f file1 ]] || echo "File does not exist?"
+BC behavior: `hg resolve --mark` accepts that the file is still there, and
+doesn't have a problem with this situation.
+  $ hg resolve --mark --config commands.resolve.mark-check=abort
+  (no more unresolved files)
+  $ hg resolve --list
+  R file1
+The file is still there:
+  $ [[ -f file1 ]] || echo "File does not exist?"
+Let's check mark-check=warn:
+  $ hg resolve --unmark file1
+  $ hg resolve --mark --config commands.resolve.mark-check=warn
+  (no more unresolved files)
+  $ hg resolve --list
+  R file1
+The file is still there:
+  $ [[ -f file1 ]] || echo "File does not exist?"
+Let's resolve the issue by deleting the file via `hg resolve`
+  $ hg resolve --unmark file1
+  $ echo 'd' | hg resolve file1 --config ui.interactive=1
+  file 'file1' was deleted in local [working copy] but was modified in other [merge rev].
+  What do you want to do?
+  use (c)hanged version, leave (d)eleted, or leave (u)nresolved? d
+  (no more unresolved files)
+  $ hg resolve --list
+  R file1
+The file is deleted:
+  $ [[ -f file1 ]] && echo "File still exists?" || true
+Doing `hg resolve --mark` doesn't break now that the file is missing:
+  $ hg resolve --mark --config commands.resolve.mark-check=abort
+  (no more unresolved files)
+  $ hg resolve --mark --config commands.resolve.mark-check=warn
+  (no more unresolved files)
+Resurrect the file, and delete it outside of hg:
+  $ hg resolve --unmark file1
+  $ hg resolve file1
+  file 'file1' was deleted in local [working copy] but was modified in other [merge rev].
+  What do you want to do?
+  use (c)hanged version, leave (d)eleted, or leave (u)nresolved? u
+  [1]
+  $ [[ -f file1 ]] || echo "File does not exist?"
+  $ hg resolve --list
+  U file1
+  $ rm file1
+  $ hg resolve --mark --config commands.resolve.mark-check=abort
+  (no more unresolved files)
+  $ hg resolve --list
+  R file1
+  $ hg resolve --unmark file1
+  $ hg resolve file1
+  file 'file1' was deleted in local [working copy] but was modified in other [merge rev].
+  What do you want to do?
+  use (c)hanged version, leave (d)eleted, or leave (u)nresolved? u
+  [1]
+  $ [[ -f file1 ]] || echo "File does not exist?"
+  $ hg resolve --list
+  U file1
+  $ rm file1
+  $ hg resolve --mark --config commands.resolve.mark-check=warn
+  (no more unresolved files)
+  $ hg resolve --list
+  R file1
+
+
+For completeness, let's try that in the opposite direction (merging r2 into r1,
+instead of r1 into r2):
+  $ hg update -qCr 1
+  $ hg merge -r 2
+  file 'file1' was deleted in other [merge rev] but was modified in local [working copy].
+  What do you want to do?
+  use (c)hanged version, (d)elete, or leave (u)nresolved? u
+  0 files updated, 0 files merged, 0 files removed, 1 files unresolved
+  use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon
+  [1]
+  $ hg resolve --list
+  U file1
+Because we left it as 'unresolved' the file should still exist.
+  $ [[ -f file1 ]] || echo "File does not exist?"
+BC behavior: `hg resolve --mark` accepts that the file is still there, and
+doesn't have a problem with this situation.
+  $ hg resolve --mark --config commands.resolve.mark-check=abort
+  (no more unresolved files)
+  $ hg resolve --list
+  R file1
+The file is still there:
+  $ [[ -f file1 ]] || echo "File does not exist?"
+Let's check mark-check=warn:
+  $ hg resolve --unmark file1
+  $ hg resolve --mark --config commands.resolve.mark-check=warn
+  (no more unresolved files)
+  $ hg resolve --list
+  R file1
+The file is still there:
+  $ [[ -f file1 ]] || echo "File does not exist?"
+Let's resolve the issue by deleting the file via `hg resolve`
+  $ hg resolve --unmark file1
+  $ echo 'd' | hg resolve file1 --config ui.interactive=1
+  file 'file1' was deleted in other [merge rev] but was modified in local [working copy].
+  What do you want to do?
+  use (c)hanged version, (d)elete, or leave (u)nresolved? d
+  (no more unresolved files)
+  $ hg resolve --list
+  R file1
+The file is deleted:
+  $ [[ -f file1 ]] && echo "File still exists?" || true
+Doing `hg resolve --mark` doesn't break now that the file is missing:
+  $ hg resolve --mark --config commands.resolve.mark-check=abort
+  (no more unresolved files)
+  $ hg resolve --mark --config commands.resolve.mark-check=warn
+  (no more unresolved files)
+Resurrect the file, and delete it outside of hg:
+  $ hg resolve --unmark file1
+  $ hg resolve file1
+  file 'file1' was deleted in other [merge rev] but was modified in local [working copy].
+  What do you want to do?
+  use (c)hanged version, (d)elete, or leave (u)nresolved? u
+  [1]
+  $ [[ -f file1 ]] || echo "File does not exist?"
+  $ hg resolve --list
+  U file1
+  $ rm file1
+  $ hg resolve --mark --config commands.resolve.mark-check=abort
+  (no more unresolved files)
+  $ hg resolve --list
+  R file1
+  $ hg resolve --unmark file1
+  $ hg resolve file1
+  file 'file1' was deleted in other [merge rev] but was modified in local [working copy].
+  What do you want to do?
+  use (c)hanged version, (d)elete, or leave (u)nresolved? u
+  [1]
+  $ [[ -f file1 ]] || echo "File does not exist?"
+  $ hg resolve --list
+  U file1
+  $ rm file1
+  $ hg resolve --mark --config commands.resolve.mark-check=warn
+  (no more unresolved files)
+  $ hg resolve --list
+  R file1
+
+  $ cd ..
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -4935,8 +4935,7 @@ 
 
             if mark:
                 if markcheck:
-                    with repo.wvfs(f) as fobj:
-                        fdata = fobj.read()
+                    fdata = repo.wvfs.tryread(f)
                     if filemerge.hasconflictmarkers(fdata) and \
                         ms[f] != mergemod.MERGE_RECORD_RESOLVED:
                         hasconflictmarkers.append(f)