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
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.