/// <summary> /// 'Pends' a delete of a folder and its contents that was previously /// checked-in and then commits that deletion to the repository. /// </summary> /// <param name="workspace">Version control workspace to use when /// deleting the folder and its contents.</param> /// <param name="newFilename">Full path to the folder to delete</param> /// <exception cref="SecurityException">If the user doesn't have /// check-in permission for the specified <paramref name="workspace"/>.</exception> /// <exception cref="IOException">If there's a problem creating the file.</exception> /// <exception cref="VersionControlException">If </exception> private static void DeleteFolder(Workspace workspace, String newFolder) { Debug.Assert(workspace != null); Debug.Assert(!String.IsNullOrEmpty(newFolder)); try { // Delete the items workspace.PendDelete(workspace.GetServerItemForLocalItem(newFolder), RecursionType.Full); var pendingDeletes = workspace.GetPendingChanges(); if (pendingDeletes.Length > 0) { workspace.CheckIn(pendingDeletes, "Clean up!"); } } catch (VersionControlException ex) { Console.Error.WriteLine("Error deleting file: {0}", ex.Message); throw; } }
public bool AddToTFVC(string[] _files, WorkItem _wi, Workspace _ws) { try { _ws.Get(); // Now add everything. _ws.PendAdd(_files, false); WorkItemCheckinInfo[] _wici = new WorkItemCheckinInfo[1]; _wici[0] = new WorkItemCheckinInfo(_wi, WorkItemCheckinAction.Associate); if (_ws.CheckIn(_ws.GetPendingChanges(), null, null, _wici, null) > 0) { _ws.Delete(); return true; } else { return false; } } catch { return false; } }
internal static void Open(List <ExtendedItem> items, Microsoft.TeamFoundation.VersionControl.Client.Workspace workspace) { using (var dialog = new CheckInDialog()) { dialog.FillStore(items, workspace); if (dialog.Run(Toolkit.CurrentEngine.WrapWindow(MessageService.RootWindow)) == Command.Ok) { using (var progress = VersionControlService.GetProgressMonitor("CheckIn", VersionControlOperationType.Push)) { progress.BeginTask("Check In", 1); var result = workspace.CheckIn(dialog.SelectedChanges, dialog.Comment, dialog.SelectedWorkItems); foreach (var failure in result.Failures.Where(f => f.SeverityType == SeverityType.Error)) { progress.ReportError(failure.Code, new Exception(failure.Message)); } progress.EndTask(); progress.ReportSuccess("Finish Check In"); } } } }
/// <summary> /// 'Pends' a change to a file that was previously checked-in and then checks /// that change into the repository. /// </summary> /// <param name="workspace">Version control workspace to use when /// changing the folder and file.</param> /// <param name="newFilename">Full path to the file to change</param> /// <exception cref="SecurityException">If the user doesn't have /// check-in permission for the specified <paramref name="workspace"/>.</exception> /// <exception cref="IOException">If there's a problem creating the file.</exception> /// <exception cref="VersionControlException">If </exception> private static void ModifyFile(Workspace workspace, String newFilename) { Debug.Assert(workspace != null); Debug.Assert(!String.IsNullOrEmpty(newFilename)); try { // Checkout and modify the file workspace.PendEdit(newFilename); using (var streamWriter = new StreamWriter(newFilename)) { streamWriter.WriteLine("Revision 2"); } // Get the pending change and check in the new revision. var pendingChanges = workspace.GetPendingChanges(); int changesetForChange = workspace.CheckIn(pendingChanges, "Modified file contents"); Console.WriteLine("Checked in changeset {0}", changesetForChange); } catch (IOException ex) { Console.Error.WriteLine("Error writing {1}: {0}", ex.Message, newFilename); throw; } catch (VersionControlException ex) { Console.Error.WriteLine("Error modifying file: {0}", ex.Message); throw; } }
/// <summary> /// 'Pends' a branch of a file that was previously checked-in and then checks /// that branch into the repository. /// </summary> /// <param name="workspace">Version control workspace to use when /// branching the folder and file.</param> /// <param name="newFilename">Full path to the file to branch</param> /// <exception cref="VersionControlException">If there's a problem performing /// the branch operation.</exception> private static void BranchFile(Workspace workspace, String newFilename) { Debug.Assert(workspace != null); Debug.Assert(!String.IsNullOrEmpty(newFilename)); String branchedFilename = Path.Combine(Path.GetDirectoryName(newFilename), Path.GetFileNameWithoutExtension(newFilename)) + "-branch" + Path.GetExtension(newFilename); workspace.PendBranch(newFilename, branchedFilename, VersionSpec.Latest, LockLevel.Checkin, true); var pendingChanges = workspace.GetPendingChanges(); int changesetForBranch = workspace.CheckIn(pendingChanges, "Branched file"); Console.WriteLine("Branched {0} to {1} in changeset {2}", newFilename, branchedFilename, changesetForBranch); }
/// <summary> /// 'Pends' the add of a new folder and file and then checks it into the /// repository. /// </summary> /// <param name="workspace">Version control workspace to use when /// adding the folder and file.</param> /// <param name="newFilename">Full path to the file to add (the path /// of the folder will be derived from the file's path.</param> /// <exception cref="SecurityException">If the user doesn't have /// check-in permission for the specified <paramref name="workspace"/>.</exception> /// <exception cref="IOException">If there's a problem creating the file.</exception> /// <exception cref="VersionControlException">If </exception> private static void AddNewFile(Workspace workspace, String newFilename) { Debug.Assert(workspace != null); Debug.Assert(!String.IsNullOrEmpty(newFilename)); Debug.Assert(!File.Exists(newFilename)); if (!workspace.HasCheckInPermission) { throw new SecurityException( String.Format("{0} does not have check-in permission for workspace: {1}", workspace.VersionControlServer.AuthenticatedUser, workspace.DisplayName)); } try { // create the new file using (var streamWriter = new StreamWriter(newFilename)) { streamWriter.WriteLine("Revision 1"); } // Now pend the add of our new folder and file workspace.PendAdd(Path.GetDirectoryName(newFilename), true); // Show our pending changes var pendingAdds = new List<PendingChange>((IEnumerable<PendingChange>) workspace.GetPendingChanges()); pendingAdds.ForEach(delegate(PendingChange add) { Console.WriteLine("\t{1}: {0}", add.LocalItem, PendingChange.GetLocalizedStringForChangeType(add.ChangeType)); }); // Checkin the items we added int changesetForAdd = workspace.CheckIn(pendingAdds.ToArray(), "Initial check-in"); Console.WriteLine("Checked in changeset {0}", changesetForAdd); } catch (IOException ex) { Console.Error.WriteLine("Error writing {1}: {0}", ex.Message, newFilename); throw; } catch (VersionControlException ex) { Console.Error.WriteLine("Error adding file: {0}", ex.Message); throw; } }
/// <summary> /// Check In all pending changes within the workspace /// </summary> /// <param name="_ws"> /// workspace with pending changes /// </param> /// <returns> /// true if check-in is successful /// </returns> public bool CheckIn(Workspace _ws) { try { _ws.CheckIn(_ws.GetPendingChanges(), null); return true; } catch { return false; } }
private static CheckInResult CheckIn(IReadOnlyCollection<PendingChange> targetPendingChanges, string comment, Workspace workspace, IReadOnlyCollection<int> workItemIds, PolicyOverrideInfo policyOverride, WorkItemStore workItemStore) { var result = new CheckInResult(); // Another user can update workitem. Need re-read before update. var workItems = GetWorkItemCheckinInfo(workItemIds, workItemStore); var evaluateCheckIn = workspace.EvaluateCheckin2(CheckinEvaluationOptions.All, targetPendingChanges, comment, null, workItems); var skipPolicyValidate = !policyOverride.PolicyFailures.IsNullOrEmpty(); if (!CanCheckIn(evaluateCheckIn, skipPolicyValidate)) { result.CheckinResult = MergeResult.CheckInEvaluateFail; } var changesetId = workspace.CheckIn(targetPendingChanges.ToArray(), null, comment, null, workItems, policyOverride); if (changesetId > 0) { result.ChangesetId = changesetId; result.CheckinResult = MergeResult.CheckIn; } else { result.CheckinResult = MergeResult.CheckInFail; } return result; }
public void WorkspaceCheckin(Workspace workspace, PendingChange[] changes, string comment, CheckinNote checkinNote, WorkItemCheckinInfo[] workItemChanges, PolicyOverrideInfo policyOverride) { this.Logger().Trace("WorkspaceCheckin"); workspace.CheckIn(changes, comment, checkinNote, workItemChanges, policyOverride); }