1

I am trying to automate creating TFS scenarios without the use of the UI dialogs that appear during merge, rollback, resolve, etc. I have a case where I neither want to AcceptYours or AcceptTheirs. I want to accept a manual merge as if the UI appeared and gave the user the chance to edit the file and accept the merge; but it's gotta be automated, no UI.

In the code below I create a 'copy' file that contains the final content I want as the manual merge for a rollback of a particular edit. As expected I get a conflict. I've tried all the tf resolve /auto: options and I can't resolve the conflict so the content from my 'copy' file is taken as though the user edited the conflict and accepted the manual merge.

  • KeepYours - will Undo the merge
  • TakeTheirs takes the server version
  • AutoMerge(Forced) - doesn't resolve the conflict
  • OverwriteLocal - doesn't resolve the conflict
  • AcceptYours - takes the version on disk but changes the change type from rollback,edit to edit

How can I reproduce a manual merge using the command line tf tool only without using the UI?

Here's an example to repro:

SET WSPATH=C:\MyMappedWorkspacePath
SET F=%WSPATH%\%RANDOM%%RANDOM%
SET TF=%ProgramFiles(x86)%\Microsoft Visual Studio 11.0\Common7\IDE\TF.exe
SET TMPFILE=%TEMP%\tf-resolve-test.txt

ECHO Hello > "%F%"
"%TF%" add "%F%"
"%TF%" checkin /comment:"add file" /noprompt "%F%" > %TMPFILE%
"%TF%" checkout "%F%"
ECHO // Change 1 >> "%F%"
COPY "%F%" "%F%-copy" > nul
"%TF%" checkin /comment:"edit 1" /noprompt "%F%" > %TMPFILE%
"%TF%" checkout "%F%"
ECHO // Change 2 >> "%F%"
"%TF%" checkin /comment:"edit 2" /noprompt "%F%" > %TMPFILE%
FOR /f %i IN ('PowerShell.exe -Command "select-string -Path %TMPFILE% -Pattern 'Changeset #(?<changeset>[0-9]*) .*' | %{$_.Matches} | %{$_.Groups['changeset']} | %{$_.Value}"') DO SET ROLLBACKCHANGESET=%i
"%TF%" checkout "%F%"
ECHO // Change 3 >> "%F%"
ECHO // Change 3 >> "%F%-copy"
"%TF%" checkin /comment:"edit 3" /noprompt "%F%" > %TMPFILE%
"%TF%" rollback /changeset:%ROLLBACKCHANGESET%~%ROLLBACKCHANGESET% "%F%" /keepmergehistory /noautoresolve /noprompt
"%TF%" resolve "%F%" /auto:DeleteConflict
DEL /F "%F%"
MOVE "%F%-copy" "%F%"
ATTRIB +R "%F%"
"%TF%" rollback /changeset:%ROLLBACKCHANGESET%~%ROLLBACKCHANGESET% "%F%" /keepmergehistory /noautoresolve /noprompt
"%TF%" resolve "%F%" /auto:AutoMergeForced /noprompt
James Reed
  • 13,873
  • 51
  • 60
bjjer
  • 43
  • 1
  • 7
  • I'm not sure you can, unless you mean that you're looking for a command line merge tool that the user can interact with? – James Reed Aug 03 '13 at 14:41

2 Answers2

0

You place to edited contents on disk, in the appropriate location, then you resolve with AcceptYours.

AcceptYours means to take your contents, as they appear on disk, not the contents of the source of the conflict.

Edward Thomson
  • 74,857
  • 14
  • 158
  • 187
  • After I checkin edit 3 I changed the order of the script I'm using after thinking about your response. I figure, why resolve twice, just put my desired content in the file before issuing the rollback. I did that, get a conflict, and as you say, I resolve with /auto:AcceptYours. I get the following: Resolved C:\myfile as KeepYours, Undoing rollback. There is nothing to checkin. I'm missing something because it makes sense to AcceptYours but why does it undo the rollback? My content is not taken. – bjjer Aug 03 '13 at 17:24
  • If you put the data in the file before you pend a change, you'll have *still another* conflict. Why are you doing two rollbacks in a row? Why are you deleting the conflict? Simply issue the rollback, place the correct data on disk, resolve the conflict and check it in...? – Edward Thomson Aug 03 '13 at 18:30
  • I sent another reply with a code sample by editing the response but it has to get approved or something like that. Anyway, I removed the first rollback (testing) and did what you said, tf responds with "Resolved as KeepYours; Undoing rollback." Then there are no pending changes to checkin. Maybe somebody will approve the edit I made soon and you can see the code. Thanks. – bjjer Aug 04 '13 at 16:10
0

I would also investigate the (command line) only option of /discard.

http://teamfoundation.blogspot.com/2007/03/discarding-changes-in-merge.html

The best way to do that is to use discard option of the merge command. The option is available only through command-line client (tf.exe) and basically performs merge without taking any changes from the source to target; its only purpose is to update the merge history between source and target and thus prevent the discarded changeset appearance in the future.

"tf.exe" merge /recursive /noprompt /discard /version:C1001~C1001 "$Source/" "$Destination/"

or

"tf.exe" merge /recursive /noprompt /discard "$Source/" "$Destination/"
granadaCoder
  • 26,328
  • 10
  • 113
  • 146