Discard candidate merge changesets

Doing parallel development across multiple branches is quite easy by creating a number of branches in TFS, but the difficult part is to setup a valid branching strategy and to enforce best practices like always pushing forward integration actions before the reverse integration operation, …

In some scenarios it will be required to avoid that individual changesets can be merged into another branch (for example configuration changes). Enter discarding candidate merges!

Using the Merge Wizard in TFS, you have the option to select the cherry-pick option to only see the changesets which haven’t been merged from Source to Target.

SNAGHTML2604bce0

SNAGHTML26095c4a

But, from the UI it’s unfortunately still not possible (TFS 2012) to discard a candidate merge changeset. I would just love to right-click on a changeset and discard it from there.

Up till now I always switched to the command-line to discard the changeset from there (tf merge /discard).

SNAGHTML260ed8b9

Recently I got a question at a customer to make this possible through the API. First of all I was a bit worried why on earth it would be necessary to automate this through the API because in the end this action should be quite exceptional. So, after going into more details it seemed that a background process was running which made a number of configuration changes to the branches, but those changesets were branch-specific and weren’t allowed to be merged into some other branch. These changesets were in fact seriously blocking the merge process due to the fact that only consecutive changesets can be merged from Source to Target and a number of these “configuration” changesets were sitting between other valid candidate merge changesets. Not good!

The solution for discarding changesets through the API is making use of the Merge method on the Workspace object. To discard, you must use the enumeration AlwaysAcceptMine as parameter for the MergeOptions. This will push the merge (without actual changes in the files) into the workspace after which the check-in can be executed. The check-in will make sure that the changeset won’t show up anymore in the candidate merge changesets.

About these ads

2 Responses to Discard candidate merge changesets

  1. Oran says:

    Thanks for the post, it’s really helpful but I have one question.

    Because it’s still required to check in the change on the “target” branch (even though there are in fact no changes) TFS creates a new changeset on the “target” branch which then appears as a merge candidate for a reverse merge.

    Seems to me like it’s only moving the problem from one place to another. Am I missing something?

    Thanks

    Oran

  2. a new changeset will indeed be created, but it will not pop up as a candidate changeset for merging in the other direction if no additional changes have been applied in the same changeset!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: