Files Vanish If Deleted Before Committing a Merge

Tony Mechelynck antoine.mechelynck at gmail.com
Sat Apr 28 02:18:09 UTC 2012


On 28/04/12 01:39, Jensen, Aaron wrote:
> Windows 7 x64, Mercurial 2.1.1.
>
> We’ve noticed that during a merge, if I delete a file (i.e. using `rm
> file`) Mercurial removes that file from the repository. There is no
> record of the file’s removal.
>
> Add a file to the default branch.  Merge that changeset into another
> branch.  Delete the new file (i.e. `rm file`) from the file system.
> Commit the merge.  The file is no longer in the branch’s manifest.  The
> log command doesn’t show the file being deleted.  However, when merging
> back to default, the file is removed and shows as removed by the log
> command.  My transcript shows this and other strange behavior [1].
>
> I would expect Mercurial to abort the commit with a warning that a file
> is missing.  Is the behavior I’m seeing by design?
>
> I observe similar behavior when committing an added file that gets
> deleted [2].

I notice that you removed a file from tracking (hg remove) between a 
merge and its commit, and that at an other point you told Mercurial that 
another file was now tracked, then removed it from the filesystem with 
no intervening commit and no "hg remove". (See below.) This is unhealthy 
in both cases.

Immediately after a merge I would expect one of only two possibilities 
(not counting change-nothing commands such as "hg status", "hg tip", "hg 
log" etc.):
- either a rollback ("I didn't mind that")
- or a commit ("Yes, I did want this merge, let's register it").

If you delete a tracked file from the filesystem it becomes missing. You 
should then use either "hg remove" or "hg addremove" to tell Mercurial 
not to track it anymore. If you don't, the repository is left in an 
inconsistent state.

Protecting you against yourself is more typical of Windows than of Unix. 
Mercurial comes from the Unix world. I guess the moral is "Garbage in, 
garbage out", or in this case, "Issue a stupid command, get a stupid 
result". I also do stupid things at times. To let me take corrective 
action before it gets too bad, I usually add some verbosity (by using 
the -v switch on commands such as rm, mv, ln, even cp; and by setting 
[ui]verbose=true in my ~/.hgrc) so for instance I'll see it immediately 
if I gave the arguments to ln in the wrong order. I also don't leave a 
Mercurial repository uncommitted for any length of time: either I commit 
the changes, I roll them back, or (if mq was enabled on this repository) 
I pop them onto some patch queue.

>
>       <:> Aaron
>
> [1] Detailed steps to reproduce:
>
> $ hg init vanish
>
> $ cd vanish
>
> $ '' > file
>
> $ hg add file
>
> $ hg commit -m "commit"
>
> $ hg branch ByeBye
>
> marked working directory as branch ByeBye
>
> (branches are permanent and global, did you want a bookmark?)
>
> $ 'a' > file
>
> $ hg commit -m .
>
> $ hg up default
>
> 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
>
> $ '' > file2
>
> $ hg add file2
>
> $ hg commit -m .
>
> $ hg up ByeBye
>
> 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
>
> $ hg merge default
>
> 1 files updated, 0 files merged, 0 files removed, 0 files unresolved
>
> (branch merge, don't forget to commit)
>
> $ rm file2
^^^^^^^^^^^^-- file removed from tracking between a merge and its commit

>
> $ hg st
>
> ! file2
>
> $ hg commit -m "Merge"
>
> $ hg st
>
> ! file2
>
> $ hg manifest
>
> file
>
> $ hg up -C
>
> 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
>
> $ hg st
>
> $ hg manifest .
>
> file
>
> $ hg log -r tip --debug
>
> changeset:   3:f2ea3a777e066e57e8871555097ba4a438ebb965
>
> branch:      ByeBye
>
> phase:       draft
>
> parent:      1:0163b8f985307d27788c3ed7621f6d7fb1644713
>
> parent:      2:ac6e8f768a50a4134167b63f1f5e4d902618c8db
>
> manifest:    1:53488d621bbd64a1d94d7ab5ff0e65b28f61c377
>
> user:        Aaron Jensen <ajensen at webmd.net>
>
> date:        Fri Apr 27 16:05:53 2012 -0700
>
> extra:       branch=ByeBye
>
> description:
>
> Merge
>
> $ hg manifest default
>
> file
>
> file2
>
> $ hg up default
>
> 2 files updated, 0 files merged, 0 files removed, 0 files unresolved
>
> $ hg merge ByeBye
>
> 1 files updated, 0 files merged, 1 files removed, 0 files unresolved
>
> (branch merge, don't forget to commit)
>
> $ hg st
>
> M file
>
> R file2
>
> $ hg commit -m "Merge"
>
> $ hg log -r tip --debug
>
> changeset:   4:423225544166efecfebdb7753fb787207d847dfa
>
> tag:         tip
>
> phase:       draft
>
> parent:      2:ac6e8f768a50a4134167b63f1f5e4d902618c8db
>
> parent:      3:f2ea3a777e066e57e8871555097ba4a438ebb965
>
> manifest:    3:6e065e75f2215faab18838302cf8832360186c5c
>
> user:        Aaron Jensen <ajensen at webmd.net>
>
> date:        Fri Apr 27 16:10:33 2012 -0700
>
> files:       file
>
> files-:      file2
>
> extra:       branch=default
>
> description:
>
> Merge
>
> $ hg manifest default
>
> file
>
> [2] Similar problem adding a deleted file:
>
> $ '' > file3
>
> $ hg add file3
^^^^^^^^^^^^^^^^-- this file is now tracked

>
> $ rm file3
^^^^^^^^^^^^-- a tracked file is removed from the filesystem without 
telling Mercurial

>
> $ hg st
>
> ! file3
^^^^^^^^^-- thus, the file is missing
>
> $ hg commit -m "adding file"
>
> nothing changed (1 missing files, see 'hg status')
>
> $ '' > file4
>
> $ hg add file4
>
> $ hg commit -m "adding file"
>
> $ hg st
>
> ! file3
^^^^^^^^^-- that file is still missing
>
> $ hg manifest
>
> file
>
> file4
>
> $ hg log --debug -r tip
>
> changeset:   5:c40266aca324f7eb8769dfe6f7bb56f4ca098576
>
> tag:         tip
>
> phase:       draft
>
> parent:      4:423225544166efecfebdb7753fb787207d847dfa
>
> parent:      -1:0000000000000000000000000000000000000000
>
> manifest:    4:bc238bdab886db77c16161344a47f68919a7dc43
>
> user:        Aaron Jensen <ajensen at webmd.net>
>
> date:        Fri Apr 27 16:22:54 2012 -0700
>
> files+:      file4
>
> extra:       branch=default
>
> description:
>
> adding file
>
> $ hg st
>
> ! file3
>
> $ hg up
>
> 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
>
> $ hg st

At this point, what is the reply to "ls -l file3"?

>
>
>
> _______________________________________________
> Mercurial mailing list
> Mercurial at selenic.com
> http://selenic.com/mailman/listinfo/mercurial
>


Best regards,
Tony.
-- 
Slick's Three Laws of the Universe:
	(1) Nothing in the known universe travels faster than a bad
	    check.
	(2) A quarter-ounce of chocolate = four pounds of fat.
	(3) There are two types of dirt: the dark kind, which is
	    attracted to light objects, and the light kind, which is
	    attracted to dark objects.



More information about the Mercurial mailing list