locked
Cut New Branch PowerShell (specific changeset)

    Question

  • Cutting a new branch using the latest changeset works as follows:

    $ChangeSetIDOutput = $VersionControlServer.CreateBranch("$SourceBranchPath", "$NewBranchPath", [Microsoft.TeamFoundation.VersionControl.Client.VersionSpec]::latest, $null, "New branch from script", $null, $null, $null)

    However, how can I specify a particular changeset to branch off of instead of using the latest?

    I tried a few things with the ChangesetVersionSpec class (https://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.changesetversionspec.aspx), but am having trouble with the syntax.

    Thanks for any help.


    Tuesday, January 31, 2017 9:50 PM

Answers

  • Hi brandonlashmet,

    Thank you for posting here.

    If you want to create branch on specified changeset, you need to use VersionSpec ParseSingleSpec methold in the following link:

    https://msdn.microsoft.com/en-us/library/bb139013(v=vs.120).aspx

    You could refer to my sample:

    $changesetId = $vcServer.CreateBranch('$/TestGao1/WpfApplication1', '$/TestGao1/Main/Branch', [Microsoft.TeamFoundation.VersionControl.Client.VersionSpec]::ParseSingleSpec("C130", "UserName"))

    Best Regards

    Limitxiao Gao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by brandonlashmet Tuesday, February 07, 2017 6:19 PM
    Thursday, February 02, 2017 6:43 AM
    Moderator

All replies

  • Cutting a new branch using the latest changeset works as follows:

    $ChangeSetIDOutput = $VersionControlServer.CreateBranch("$SourceBranchPath", "$NewBranchPath", [Microsoft.TeamFoundation.VersionControl.Client.VersionSpec]::latest, $null, "New branch from script", $null, $null, $null)

    However, how can I specify a particular changeset to branch off of instead of using the latest?

    I tried a few things with the ChangesetVersionSpec class (https://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.changesetversionspec.aspx), but am having trouble with the syntax.

    Thanks for any help.

    Wednesday, February 01, 2017 5:30 PM
  • Hi brandonlashmet,

    Thank you for posting here.

    If you want to create branch on specified changeset, you need to use VersionSpec ParseSingleSpec methold in the following link:

    https://msdn.microsoft.com/en-us/library/bb139013(v=vs.120).aspx

    You could refer to my sample:

    $changesetId = $vcServer.CreateBranch('$/TestGao1/WpfApplication1', '$/TestGao1/Main/Branch', [Microsoft.TeamFoundation.VersionControl.Client.VersionSpec]::ParseSingleSpec("C130", "UserName"))

    Best Regards

    Limitxiao Gao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by brandonlashmet Tuesday, February 07, 2017 6:19 PM
    Thursday, February 02, 2017 6:43 AM
    Moderator
  • Great, thanks. I'll test it out.
    Friday, February 03, 2017 10:19 PM
  • Hi Limitxiao,


    I tried the following:

    $ChangeSetIDOutput = $VersionControlServer.CreateBranch("$SourceBranchPath", "$NewBranchPath", [Microsoft.TeamFoundation.VersionControl.Client.VersionSpec]::ParseSingleSpec("$ChangeSetID", "UserName"), $null, "New branch from script", $null, $null, $null)

    I'm passing the $ChangeSetID in from the command line like this:


    CutReleaseBranch -ProjectPath '$/path/to/project' -BranchToCut 'Main' -ChangeSetID '310165' -ReleaseDate 'BLTest'

    And it works great.

    After the branch is cut, any ideas how to merge multiple changesets into it? Maybe there's a different method I could use after?

    Thanks for your help.



    Monday, February 06, 2017 7:30 PM
  • Hi brandonlashmet,

    You could try to use the workspace.Merge to merge changeset branch in the following link:

    https://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.workspace.merge(v=vs.120).aspx

    Best Regards

    Limitxiao Gao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, February 07, 2017 8:09 AM
    Moderator
  • Hi Limitxiao,

    Thanks for the link.  Could you help me with the syntax on this one?

    Either merging multiple changesets from one branch to another, or multiple changesets one at a time from one branch to another?

    I'm also wondering if there is a method to check the changes in after they are merged to the new branch.

    Thank you for your help.


    Tuesday, February 07, 2017 6:19 PM
  • Hi brandonlashmet,

    You could use this method:

    Workspace.Merge Method (sourcePath, targetPath, versionFrom, versionTo), you could only merge a contiguous set of changes.

    Please refer to this link:

    https://msdn.microsoft.com/en-us/library/bb139330(v=vs.120).aspx

    Best Regards

    Limitxiao Gao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, February 08, 2017 6:57 AM
    Moderator
  • Thanks, but the changes need to be checked in after the merge, correct?  Is there a method for checking in the changes as well, after the merge?
    Wednesday, February 08, 2017 7:00 AM
  • Hi brandonlashmet,

    Yes, use this method to check-in the changes:

    https://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.workspace.checkin(v=vs.120).aspx

    Before that you need to get the pending changes via the following method:

    https://msdn.microsoft.com/en-us/library/microsoft.teamfoundation.versioncontrol.client.workspace.getpendingchanges(v=vs.120).aspx

    Best Regards

    Limitxiao Gao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, February 08, 2017 7:07 AM
    Moderator
  • Hi Limitxiao Gao,

    Can you explain how to use the workspace.merge method?

    Suppose I cut a branch B3 from B2 using the latest code from B2.

    Then, I want to merge a single changeset C1 from branch B1 to B3.

    I assume the syntax is as follows:

    Workspace.Merge("B1", "B3", C1, C1)

    However, how do I instantiate the Workspace and get the versionspec object C1?

    Maybe something like $Workspace = New-Object Microsoft.TeamFoundation.Client.TeamFoundationServer("$WorkspaceName"),

    Then $Workspace.Merge("B1", "B3", C1, C1)?

    Thank you.

    Friday, March 10, 2017 11:44 PM
  • Hi Limitxiao Gao,

    Any ideas on my previous inquiry?

    Thank you.


    Friday, March 24, 2017 5:26 PM
  • Hi,

    Sorry for the delay. You could refer to the following thread:

    http://stackoverflow.com/questions/12092854/how-to-merge-tfs-change-sets-programmatically

    Best Regards

    Limitxiao Gao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, March 27, 2017 9:33 AM
    Moderator