/// <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; } }
private void DeleteItems(List <ExtendedItem> items) { List <Failure> failures; _currentWorkspace.PendDelete(items.Select(x => (FilePath)x.LocalItem).ToList(), RecursionType.Full, false, out failures); if (failures.Any(f => f.SeverityType == SeverityType.Error)) { FailuresDisplayDialog.ShowFailures(failures); } FireFilesRemoved(items); RefreshList(items); }
public override void Run() { // must get server<->local mappings for GetServerItemForLocalItem workspace = GetWorkspaceFromCache(); workspace.RefreshMappings(); // by default, if nothing specified we process all changes if ((!OptionModified) && (!OptionDeleted) && (!OptionAdded)) { OptionModified = OptionAdded = OptionDeleted = true; } Online(Arguments); if (OptionPreview) return; int changes = 0; changes += workspace.PendAdd(addedFiles.ToArray(), false); changes += workspace.PendEdit(editedFiles.ToArray(), RecursionType.None); changes += workspace.PendDelete(deletedFiles.ToArray(), RecursionType.None); Console.WriteLine("{0} pending changes.", changes); }
private static bool AddMissingFile(XDocument xml, FileInfo file, string rootPath, string relativePath, string linkPath, Workspace workspace) { var compileName = XName.Get("Compile", ProjectNs); var newFilePath = Path.Combine(relativePath, file.NewName); var itemGroup = xml.Descendants(compileName).FirstOrDefault().Parent; if (itemGroup.Descendants(compileName).Any(x => x.Attributes().Any(a => a.Value.Contains(newFilePath)))) { return false; } if (!string.IsNullOrEmpty(file.OldName)) { var oldFilePath = Path.Combine(relativePath, file.OldName); var oldCompileInfo = itemGroup.Descendants(compileName).FirstOrDefault(x => x.Attributes().Any(a => a.Value.Contains(oldFilePath))); if (oldCompileInfo != null) { oldCompileInfo.Remove(); if (workspace != null) { workspace.PendDelete(Path.Combine(rootPath, oldFilePath)); } else { var oldFileInfo = new System.IO.FileInfo(Path.Combine(rootPath, oldFilePath)); oldFileInfo.Delete(); } } } var compileInfo = new XElement(compileName); compileInfo.Add(new XAttribute(XName.Get("Include"), newFilePath)); if (linkPath != null) { var fileLinkPath = Path.Combine(linkPath, file.NewName); compileInfo.Add(new XElement(XName.Get("Link", ProjectNs), fileLinkPath)); } itemGroup.Add(compileInfo); if (workspace != null && linkPath == null) { workspace.PendAdd(Path.Combine(rootPath, newFilePath)); } return true; }
public override void Run() { workspace = GetWorkspaceFromCache(); workspace.RefreshMappings(); if (Arguments.Length < 1) { Console.WriteLine("No changeset specified."); Environment.Exit((int)ExitCode.Failure); } int cid = Convert.ToInt32(Arguments[0]); Changeset changeset = VersionControlServer.GetChangeset(cid, true, false); // fetch all items in one fell swoop List<int> ids = new List<int>(); foreach (Change change in changeset.Changes) { if ((change.ChangeType & ChangeType.Add) == ChangeType.Add) { if (change.Item.ItemType != ItemType.Folder) { string localItem = workspace.GetLocalItemForServerItem(change.Item.ServerItem); Console.WriteLine("Undo add: " + change.Item.ServerItem); deletedFiles.Add(localItem); } continue; } ids.Add(change.Item.ItemId); } ProcessEdits(changeset, ids.ToArray(), cid); if (OptionPreview) return; changeCount += workspace.PendAdd(addedFiles.ToArray(), false); changeCount += workspace.PendEdit(editedFiles.ToArray(), RecursionType.None); changeCount += workspace.PendDelete(deletedFiles.ToArray(), RecursionType.None); Console.WriteLine("{0} pending changes.", changeCount); }