[PATCH] commit: abort on merge with missing files

Matt Mackall mpm at selenic.com
Sat Apr 28 11:35:50 CDT 2012


On Sat, 2012-04-28 at 15:02 +0200, Patrick Mezard wrote:
> # HG changeset patch
> # User Patrick Mezard <patrick at mezard.eu>
> # Date 1335618117 -7200
> # Branch stable
> # Node ID 63c817ea4a70a977a212cb01c8ec13a7e1ee59a2
> # Parent  39d1f83eb05d424fc467d2e0eece8c4a8cefd35a
> commit: abort on merge with missing files

Nice, queued for stable.

> Here is a script illustrating the previous behaviour:
> 
> The merge brings a new file 'b' from remote
>   $ hg merge 1 --debug
>     searching for copies back to rev 1
>     unmatched files in other:
>      b
>   resolving manifests
>    overwrite: False, partial: False
>    ancestor: 07f494440405, local: 540395c44225+, remote: 102a90ea7b4a
>    b: remote created -> g
>   updating: b 1/1 files (100.00%)
>   getting b
>   1 files updated, 0 files merged, 0 files removed, 0 files unresolved
>   (branch merge, don't forget to commit)
> 
> Delete but do not remove b
>   $ rm b
>   $ hg st
>   ! b
> 
> The commit succeeds
>   $ hg commit -m merge
>   $ hg parents --template "{rev} {desc|firstline} files: {files}\n"
>   3 merge files:
>   $ hg st
>   ! b
> 
> b changes were ignored, but even b existence was ignored
>   $ hg manifest
>   a
> 
> This happens because localrepo.commitctx() checks the input ctx.files(), which
> is empty for workingctx.files() only returns added, modified or removed
> entries, and bypass files/manifest updates completely. So the committed
> revision manifest is the same as its first parent one, not containing the 'b'
> file.
> 
> This patch forces the commit to abort in presence of a merge and missing files.
> test-merge4.t is modified accordingly as it was introduced to check hg was not
> just terminating with a traceback (5e9e8b8d2629).
> 
> diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
> --- a/mercurial/localrepo.py
> +++ b/mercurial/localrepo.py
> @@ -1147,6 +1147,9 @@
>                  and wctx.branch() == wctx.p1().branch()):
>                  return None
>  
> +            if merge and changes[3]:
> +                raise util.Abort(_("cannot commit merge with missing files"))
> +
>              ms = mergemod.mergestate(self)
>              for f in changes[0]:
>                  if f in ms and ms[f] == 'u':
> diff --git a/tests/test-merge4.t b/tests/test-merge4.t
> --- a/tests/test-merge4.t
> +++ b/tests/test-merge4.t
> @@ -16,5 +16,10 @@
>    (branch merge, don't forget to commit)
>    $ rm b
>    $ echo This is file c22 > c
> +
> +Test hg behaves when committing with a missing file added by a merge
> +
>    $ hg commit -m "commit #3"
> +  abort: cannot commit merge with missing files
> +  [255]
>  
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel


-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list