locked
Merge after rename operation RRS feed

  • Question

  • Hi All,

    I have a scenario that I can't resolve on TFS 2010.

    I have a script that merges between two relational branches; the script takes only the last revision of each file in my collection and merges him to the target branch.

    My problem comes when I have pending change of "Rename" that I'm trying to merge.

    For example:

    I have two relational branches A and B

    Each branch has the same file : X.cs

    On branch A I did what described below:

    X.cs(Rev1) -> [Renamed] X_afterRename.cs (Rev2)

    Now, I'm trying to pass (merge) the X_afterRename.cs file to my target Branch - B

    I know that if I'm going up to the folder that on top of X_afterRename.cs file, the merge operation will work as expected and the target file on Branch B will rename his file X.cs ->] X_afterRename.cs as expected.

    The problem is that on my script I cant go up to the folder that on top of my file and merge recursively...I'm willing to merge only the file that renamed.

    Is there any way to give my merge command (tf.exe or API) only the file from my source branch and the command will merge the file and renamed the target branch as expected??

    Why the merge needs the folder that on top of my file to implement the merge action??

    Why can't I merge the file directly??

    Any help will be much appreciated.

    Thanks in advance,

    Shmulik.

     

     

     

     

     

     

     

     

    Wednesday, February 17, 2010 7:10 PM

Answers

  • Hi Shmulik,
    Your intuition about using a label to get around this limitation was a great idea. The trick is to add the source of the rename to the label at the changeset when it was renamed. This item will then exist in the label in a deleted state (a new feature in TFS 2010). Then original.txt can be matched with renamed.txt and merged to the target branch as a rename, instead of a branch.

    D:\Proj\mergetest>mkdir source

    D:\Proj\mergetest>cd source

    D:\Proj\mergetest\source>copy con original.txt
    asdf
    ^Z
            1 file(s) copied.

    D:\Proj\mergetest\source>tf add original.txt
    original.txt

    D:\Proj\mergetest\source>tf checkin . /r /i /comment:"Source branch"
    Checking in add: original.txt

    Changeset #22 checked in.

    D:\Proj\mergetest\source>cd ..

    D:\Proj\mergetest>tf branch source target
    target

    target:
    original.txt

    D:\Proj\mergetest>tf checkin . /r /i /comment:"Target branch"
    Checking in branch: target

    target:
    Checking in branch: original.txt

    Changeset #23 checked in.

    D:\Proj\mergetest>cd source

    D:\Proj\mergetest\source>tf rename original.txt renamed.txt
    renamed.txt

    D:\Proj\mergetest\source>tf checkin . /r /i /comment:"Rename in source branch"
    Checking in rename: renamed.txt

    Changeset #24 checked in.

    D:\Proj\mergetest\source>tf label MergeRename@$/Proj renamed.txt
    Created label MergeRename@$/Proj

    D:\Proj\mergetest\source>tf label MergeRename@$/Proj original.txt;C24
    Updated label MergeRename@$/Proj

    D:\Proj\mergetest\source>tf label MergeRename@$/Proj .
    Updated label MergeRename@$/Proj

    D:\Proj\mergetest\source>cd ..

    D:\Proj\mergetest>tf merge /r source;LMergeRename@$/Proj target
    merge, rename: $/Proj/mergetest/source/renamed.txt;C24~C24 -> $/Proj/mergetest/target/original.txt;C23

    D:\Proj\mergetest>

    Thursday, February 18, 2010 2:39 PM

All replies

  • Hello,
    when you are merging a rename you should specify common parent of the source and target (it's not just parent if it's a move). Otherwise new file will be merged as branch and old file as delete. The only solution that I can think of is to merge parent specifying versionFrom and versionTo to narrow down changes and then undo changes that you don't want.

    Hope this helps
    Michal Malecki TFS Version Control Client
    Wednesday, February 17, 2010 10:19 PM
  • Thanks Michal,

    I am afraid this is not really possible from my script, because, I might have pending changes on the Target branch  that will cause my merge to fail.

    I tried to do something else and even that doesn't work for me...

    I tried to add Label on my renamed file + the up folder that on top of my renamed file and then I tried to merge based on that Label.

    I was expect to get the wanted behavior, but unfortunately it branched my renamed file and didn't renamed the target file :-(

    Can you explain why does it happen??

    Any other suggestions will be much welcome.

    Thanks.

    Thursday, February 18, 2010 8:53 AM
  • Hi Shmulik,
    Your intuition about using a label to get around this limitation was a great idea. The trick is to add the source of the rename to the label at the changeset when it was renamed. This item will then exist in the label in a deleted state (a new feature in TFS 2010). Then original.txt can be matched with renamed.txt and merged to the target branch as a rename, instead of a branch.

    D:\Proj\mergetest>mkdir source

    D:\Proj\mergetest>cd source

    D:\Proj\mergetest\source>copy con original.txt
    asdf
    ^Z
            1 file(s) copied.

    D:\Proj\mergetest\source>tf add original.txt
    original.txt

    D:\Proj\mergetest\source>tf checkin . /r /i /comment:"Source branch"
    Checking in add: original.txt

    Changeset #22 checked in.

    D:\Proj\mergetest\source>cd ..

    D:\Proj\mergetest>tf branch source target
    target

    target:
    original.txt

    D:\Proj\mergetest>tf checkin . /r /i /comment:"Target branch"
    Checking in branch: target

    target:
    Checking in branch: original.txt

    Changeset #23 checked in.

    D:\Proj\mergetest>cd source

    D:\Proj\mergetest\source>tf rename original.txt renamed.txt
    renamed.txt

    D:\Proj\mergetest\source>tf checkin . /r /i /comment:"Rename in source branch"
    Checking in rename: renamed.txt

    Changeset #24 checked in.

    D:\Proj\mergetest\source>tf label MergeRename@$/Proj renamed.txt
    Created label MergeRename@$/Proj

    D:\Proj\mergetest\source>tf label MergeRename@$/Proj original.txt;C24
    Updated label MergeRename@$/Proj

    D:\Proj\mergetest\source>tf label MergeRename@$/Proj .
    Updated label MergeRename@$/Proj

    D:\Proj\mergetest\source>cd ..

    D:\Proj\mergetest>tf merge /r source;LMergeRename@$/Proj target
    merge, rename: $/Proj/mergetest/source/renamed.txt;C24~C24 -> $/Proj/mergetest/target/original.txt;C23

    D:\Proj\mergetest>

    Thursday, February 18, 2010 2:39 PM
  • Many Thanks - it works!!
    Sunday, February 21, 2010 9:09 AM