tags:

views:

429

answers:

1

Say I have branch A in TFS from which I take branch B. Some changesets are made on B, then from B, branch C is taken, and more changes are made on branch C

A ------------------------------
     |
B    ----1--2------------------
                 |
C                ----3-----4---

Now suppose we want to merge from C into A, but bypassing B. TFS won't allow this - I have to do a baseless merge, which can be very error prone. Really, I want to get C "reparented" (if that is the correct terminology) so it is a child of A, not B. In other words, I want to end up with the following branch structure. (C' can either be the original C branch, or a new branch that is what C should have been).

A ------------------------------
     |   |
B    |   ----1--2------------------
     |           
C'   |-------1--2----3-----4---

Now C' can be merged correctly into A without going into B.

My question is, is there any automated tool / script that could set up the pending changes required to create the C' branch, as to manually do this would take us a very long time?

+2  A: 

Reparenting a branch in TFS is hard. You can effectively give it an additional parent via baseless merge, but:

  • baseless merges are tedious & error prone, as you know
  • there is no command or API for removiong the merge relationship with the "real" parent, short of Destroy
  • you will not be able to perform merges in the new direction via the VS 2005/2008 Merge Wizard

What you seem to be asking for -- and I agree is the best solution -- is a brand new branch named C' that happens to have the same contents that C does today. Here's a quick way to achieve that:

  1. Use the normal Branch dialog to create the new branch. If it must have the same name as C, that's ok, just rename C to C_old first. You'll need to decide whether it's appropriate to branch from Latest or from some older version of A. (If it helps, you can see the version that B was branched from in the Properties dialog.)
  2. Delete the new C directory from disk.
  3. Navigate a command prompt to the C_old directory, then run tfpt scorch -diff -deletes. This will ensure C_old is up to date and does not contain any extraneous files (e.g. build artifacts).
  4. Copy C_old -> C.
  5. Navigate to C, then run tfpt online -adds -deletes -diffs . -r. This will pend adds, edits, & deletes as necessary for the server to record the delta between A [as branched] and C [as represented on disk].
  6. Checkin

The only disadvantage of this method is that you won't see changes 3 & 4 in the history. They'll still be under C_old, of course, but tools like Annotate won't know that -- they'll see those changes as occurring all at once, on the date you created C', without the individual comments/work items/etc.

Richard Berg
great answer, thanks. we just soldiered on with fixing the baseless merge conflicts this time, but the the tfpt online command looks like it could be a very useful one to remember for future.
Mark Heath