views:

59

answers:

2

I have a Mercurial repository with four branches in it. One is the "common" branch, the other three are "specific" branches which consist of some cosmetic changes applied to the common branch. One of those cosmetic changes consisted of renaming some files.

So the common branch has "file.txt", and the first specific branch has "file-01.txt" which is the same file, used for the same purpose but has a different name and slightly different contents. It was renamed to file-01.txt on the specific branch, and "hg log -f file-01.txt" correctly shows the history going back to before the rename.

When I make a change to file.txt on the common branch, I need to be able to merge that change into file-01.txt on the specific branch. But Mercurial doesn't understand that the files are the same. It tells me:

remote changed file.txt which local deleted

use (c)hanged version or leave (d)eleted?

If I pick "c" then I get a new file.txt containing exactly what's in the common branch's version. If I pick "d" then the change isn't merged at all.

What can I do to get this right?


EDIT: I can make it work correctly in a fresh test repository, but not my actual repo. Here's what I get (note that rev 118 is on the specific branch, just before the original rename, so I'm going through the rename process again to illustrate):

C:\...> hg update -C 118

0 files updated, 0 files merged, 0 files removed, 0 files unresolved

C:\...> hg merge default

merging file.txt
merging anotherfile.txt
0 files updated, 2 files merged, 0 files removed, 0 files unresolved
(branch merge, don't forget to commit)

So it works without the rename. But if I rename, it fails:

C:\...> hg update -C 118

2 files updated, 0 files merged, 0 files removed, 0 files resolved

C:\...> hg rename file.txt file-01.txt
C:\...> hg commit -m "renamed"

created new head

C:\...> hg merge default

remote changed file.txt which local deleted
use (c)hanged version or leave (d)eleted?


EDIT 2: Here's what I get at that last step from hg merge --debug default:

searching for copies back to rev 115
unmatched files in local:
file-01.txt
all copies found (* = to merge, ! = divergent):
file-01.txt -> file.txt

checking for directory renames
resolving manifests
overwrite None partial False
ancestor 9d979018c2df local f842fdbc252b+ remote 05fc75e480da
anotherfile.txt: versions differ -> m
remote changed file.txt which local deleted
use (c)hanged version or leave (d)eleted?

A: 

The problem is with how you handed the rename in the branch. From the looks of it you (or your GUI) did a 'remove' on the old name, file.txt, and then did an add of a copy of that file named file-01.txt.

When you do it that way, mercurial has no idea they're linked. If, however, you had, in the branch, used the command:

hg rename file.txt file-01.txt

then rather than the message you're seeing the changes from file.txt would be applied to file-01.txt. However, without your help mercurial can't know they're linked.

Ry4an
"handed" -> "handled"?
Geoffrey Zheng
I don't know what is wrong, but he says `hg log -f file-01.txt` correctly follows the history back through the *rename*... that makes me believe he did rename it correctly.
Martin Geisler
Yeah, I'm guessing it was renamed in file browser GUI and then got the add/remove from an IDE. If I'm wrong then it's definitely something deeper, but my guess is 'hg rename' wasn't used. Admittedly it's a hunch.
Ry4an
IIRC I used the Rename feature in TortoiseHg -- it would've been either that or the Guess Renames feature. I'll play around to see if that works differently from `hg rename`
Jesse McGrew
See the edited question - it works if I create a fresh test repo to play around with, but I get the same error in my actual repo whether I use `hg rename` or TortoiseHg's Rename feature. The log definitely shows the file being copied to the new name and deleted under the old name (which is how Hg represents renames, right?). I can't see any notable differences in the logs between the repo where this works and the one where it fails.
Jesse McGrew
In your original repo when you do a 'hg log -p --git' on the changeset where the rename happened does it say "renamed" or does it show as a delete and an add?
Ry4an
It shows "rename from file.txt" followed by "rename to file-01.txt".
Jesse McGrew
BTW, I've been redacting the file names - the file in question is actually in a subdirectory, if that matters. It hasn't been moved in or out, just renamed within the directory.
Jesse McGrew
Hrm, then my guess was wrong. It sounds like you did it right to begin with. I'd delete this answer, but it has some stuff in the comments that might help others come up with a good one.
Ry4an