Reputation: 5323
EDIT: poor wording of my question. What I am trying to achieve is to 'discard' the merge history of the changeset
EDIT 2 I worked out how I can remove the changeset from the merge candidate queue. I don't particularly think it is a good idea but I am including the code simply for 'completeness' sake.
SCENARIO: developer fixes bug on branch and checks in. Developer then fixes bug on trunk instead of merging (trunk has changed dramatically therefore not merging). However the changeset appears in the list when merging from the branch to the trunk. I am trying to mark this changeset to remove it from this list. This can be done using the commandline utility by passing the 'discard' switch...I am tryinh to achive the same using the TFS API..
I think I am pretty close by use of the Merge method but am not sure of the options to pass in. I do NOT want to perform a merge just want to mark the changeset as merged without merging
have got a list of changesets from TFS using a Winforms app and would like be able to merge a changeset by calling discard on it using C#
the merge command is here
can this be done using the TFS .NET libraries or do I have to call the commandline editor from the winforms app?
//get the merge candidates
IEnumerable<MergeCandidate> mergeCandidates =
_vcs.GetMergeCandidates(cboSource.Text, cboTarget.Text, RecursionType.Full)
.OrderByDescending(x => x.Changeset.ChangesetId)
.AsEnumerable();
//user select a changeset from a grid and then I want to discard this changeset from the //'merge list'
string _changeset = grdChangeSets.CurrentRow.Cells[0].Value.ToString();
VersionSpec vfrom = VersionSpec.ParseSingleSpec(_changeset, null);
VersionSpec vto = VersionSpec.ParseSingleSpec(_changeset,null);
_workspaces[0].Merge(cboSource.Text, cboTarget.Text, vfrom, vto, LockLevel.None, RecursionType.Full,
MergeOptions.AlwaysAcceptMine);
EDIT 2 CODE
string _changeSetId = grdChangeSets.CurrentRow.Cells[0].Value.ToString();
VersionSpec vfrom = VersionSpec.ParseSingleSpec(_changeSetId, null);
VersionSpec vto = VersionSpec.ParseSingleSpec(_changeSetId, null);
UsiWorkspace wksp = new UsiWorkspace();
wksp.ResolveConflicts(_workspaces[0]);
GetStatus getStatus = _workspaces[0].Merge(cboSource.Text,
cboTarget.Text,
vfrom,
vto,
LockLevel.None,
RecursionType.Full,
MergeOptions.AlwaysAcceptMine);
var _conflicts = workspaces[0].QueryConflicts(null, true);
foreach (Conflict conflict in _conflicts)
{
conflict.Resolution = Resolution.DeleteConflict;
workspace.ResolveConflict(conflict);
}
var wip = new WorkspaceCheckInParameters(_workspaces[0].GetPendingChanges(),string.Format("CHECKED IN FROM TFS TOOL - {0} {1}", DateTimeOffset.Now.ToString(), Environment.UserName))
{
OverrideGatedCheckIn = ((CheckInOptions2) _vcs.SupportedFeatures & CheckInOptions2.OverrideGatedCheckIn) ==
CheckInOptions2.OverrideGatedCheckIn,
PolicyOverride = new PolicyOverrideInfo("CHECKED IN FROM TFS TOOL - POLICY", null)
};
_workspaces[0].CheckIn(wip);
Upvotes: 1
Views: 1539
Reputation: 31147
There is a merge method in the TFS api : http://msdn.microsoft.com/en-us/library/ff731634.aspx
Perhaps something like this :
var status = _workspace.Merge(sourceTfsPath, targetTfsPath, null, null, LockLevel.None, RecursionType.Full,
MergeOptions.AlwaysAcceptMine);
Trace.WriteLine(status.NumOperations);
var conflicts = _workspace.QueryConflicts(null, true);
foreach (var conflict in conflicts)
{
conflict.Resolution = Resolution.AcceptYours;
_workspace.ResolveConflict(conflict);
}
Upvotes: 3