public void Workspace_RefreshMappings2() { // need TFS_ envvars for this test if (String.IsNullOrEmpty(tfsUrl)) { return; } TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials); VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer)); WorkingFolder[] folders = new WorkingFolder[1]; string serverItem = String.Format("$/{0}", Environment.GetEnvironmentVariable("TFS_PROJECT")); folders[0] = new WorkingFolder(serverItem, Environment.CurrentDirectory); Workspace w1 = vcs.CreateWorkspace("CreateDelete1_Workspace", Environment.GetEnvironmentVariable("TFS_USERNAME"), "My Comment", folders, Environment.MachineName); //Workstation.Current.UpdateWorkspaceInfoCache(vcs, Environment.GetEnvironmentVariable("TFS_USERNAME")); WorkspaceInfo info = Workstation.Current.GetLocalWorkspaceInfo(Environment.CurrentDirectory); Workspace w2 = info.GetWorkspace(tfs); // this will talk to the server and get the mapped paths // BUT it will fail because we don't pass a full path like in RefreshMappings1 w2.RefreshMappings(); string serverItem2 = w2.TryGetServerItemForLocalItem("foo.txt"); Assert.IsNull(serverItem2); w1.Delete(); }
public void Workspace_TryGetWorkingFolderForServerItem() { // need TFS_ envvars for this test if (String.IsNullOrEmpty(tfsUrl)) { return; } TeamFoundationServer tfs = new TeamFoundationServer(tfsUrl, credentials); VersionControlServer vcs = (VersionControlServer)tfs.GetService(typeof(VersionControlServer)); WorkingFolder[] folders = new WorkingFolder[2]; string serverItem = String.Format("$/{0}", Environment.GetEnvironmentVariable("TFS_PROJECT")); folders[0] = new WorkingFolder(serverItem, Environment.CurrentDirectory); string deeper = Path.Combine(Environment.CurrentDirectory, "deeper"); folders[1] = new WorkingFolder(serverItem + "/deeper", deeper); Workspace w1 = vcs.CreateWorkspace("CreateDelete1_Workspace", Environment.GetEnvironmentVariable("TFS_USERNAME"), "My Comment", folders, Environment.MachineName); WorkspaceInfo info = Workstation.Current.GetLocalWorkspaceInfo(Environment.CurrentDirectory); Workspace w2 = info.GetWorkspace(tfs); // this will talk to the server and get the mapped paths w2.RefreshMappings(); { string serverItem1 = String.Format("{0}/deeper/foo.txt", serverItem); WorkingFolder folder = w2.TryGetWorkingFolderForServerItem(serverItem1); Assert.AreEqual(deeper, folder.LocalItem); } { string serverItem1 = String.Format("junk/deeper/foo.txt", serverItem); WorkingFolder folder = w2.TryGetWorkingFolderForServerItem(serverItem1); Assert.IsNull(deeper); } w1.Delete(); }
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); }
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); }