2

I have two branches, Apple and Banana. Out of all the unmerged changesets in Apple, I only want to merge those that contain the term MergeToBanana in their check-in comments.

So far this is what I have in my PowerShell script:

Param (       
       [Parameter(Mandatory=$true)]
       [String]$ChangesetComment
       )

$tf = get-item "c:\program files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\TF.EXE"

if ($ChangesetComment) {
    echo "*** Looking for all changesets containing '$ChangesetComment' in their check-in comments. This might take a while. ***"
    $changesetsToMerge = & $tf history $/TeamProject/Server/Apple /noprompt /recursive | findstr $ChangesetComment  
    $changesetNumbers = $changesetsToMerge | % $_.changesetnumber

    echo "*** Now merging filtered changesets. ***"
    Foreach ($c in $changesetNumbers) {
        & $tf merge /version $_.c $/IMSDev/Closed/$ScdVersion . /r /noprompt    
    }
}

Given my example, ChangesetComment will be set to MergeToBanana when I run the script.

I would like to modify my tf history command so that it only yields information about changesets in Apple that are not yet merged into Banana, so that I don't have to search through the entire history for changesets that contain ChangesetComment in their check-in comments. How can I do so?

Any other advice on how to improve my script is also welcome.

M.Y. Babt
  • 2,733
  • 7
  • 27
  • 49

1 Answers1

0

Instead of using the tf history command, you could try to use /candidate option in TF merge command

tf merge /candidate SOURCE_BRANCH TARGET_BRANCH

Example:

tf merge /candidate Apple Banana

More detai ways please refer the answers in this question: TFS: List changesets that have not been merged

Community
  • 1
  • 1
PatrickLu-MSFT
  • 49,478
  • 5
  • 35
  • 62