a question about file renaming

Christian Boos cboos at neuf.fr
Thu Jul 10 05:43:10 CDT 2008


Peter Arrenbrecht wrote:
> On Thu, Jul 10, 2008 at 10:41 AM, Manlio Perillo
> <manlio.perillo at gmail.com> wrote:
>   
>> Hi.
>>
>> I have a small question about this use case:
>>
>> 1) Create a file named 'x' with content "x", add to repository and
>>    commit
>> 2) Rename file 'x' to 'y', create and add to repository a new file 'x'
>>    with content "new x", commit
>>
>>
>> Is this fully supported?
>>     
>
> Think so. Just tested and could clone ok.
>
>   
>> The diff says:
>>
>> diff --git a/x b/x
>> --- a/x
>> +++ b/x
>> @@ -1,1 +1,1 @@
>> -x
>> +new x
>>     

I'm under the impression that the original poster meant that the above 
diff was actually wrong, and that re-adding a file which has been 
''renamed'' (as opposed to copied) should show as an add, not a as a 
modification (he said "add to repository a new file 'x'").

I did some testing as well, and after doing `hg ren x y`, status shows:
A y
R x

If this is immediately followed by an add (without intervening commit), 
we'll see:
M x
A y

i.e. hg thinks that x's removal has been cancelled by the add.
So you're actually turning a rename into a copy.

This behavior seems perfectly right to me. If one wants a real rename 
followed by an add, this should be done in two separate commits. If you 
do so, hg st --rev <rev-before-re-adding> will show, as expected:
A x

`hg log -r<rev-of-adding> -p` will show you, as expected:
diff --git a/x b/x
new file mode 100644
--- /dev/null
+++ b/x
@@ -0,0 +1,1 @@
+new x

The only glitch is that a plain `hg log x` will not give you any hint 
about the re-adding
(but `hg log --debug x` will, as x will be listed under files+ for the 
first and second add).

-- Christian



More information about the Mercurial mailing list