public override void Run() { string path = Environment.CurrentDirectory; if (Arguments.Length > 0) { path = Arguments[0]; } if (!VersionControlPath.IsServerItem(path)) { path = Path.GetFullPath(path); } // process command options RecursionType rtype = OptionRecursive ? RecursionType.Full : RecursionType.OneLevel; DeletedState dstate = OptionDeleted ? DeletedState.Any : DeletedState.NonDeleted; ItemSpec itemSpec = new ItemSpec(path, rtype); ItemSet itemSet = VersionControlServer.GetItems(itemSpec, VersionFromString(OptionVersion), dstate, ItemType.Any, false); Item[] items = itemSet.Items; foreach (Item item in items) { Console.Write(item.ServerItem); if ((item.ItemType == ItemType.Folder) && (!item.ServerItem.EndsWith(Path.DirectorySeparatorChar.ToString()))) { Console.Write("/"); } Console.WriteLine(); } Console.WriteLine(items.Length + " item(s)"); }
public override void Run() { RecursionType rtype = OptionRecursive ? RecursionType.Full : RecursionType.None; VersionSpec version = VersionFromString(OptionVersion); List <ItemSpec> itemSpecs = new List <ItemSpec>(); foreach (string item in Arguments) { string fpath = (VersionControlPath.IsServerItem(item))? item : Path.GetFullPath(item); itemSpecs.Add(new ItemSpec(fpath, rtype)); } BranchHistoryTreeItem[][] treeItemsArray = VersionControlServer.GetBranchHistory(itemSpecs.ToArray(), version); foreach (BranchHistoryTreeItem[] treeItems in treeItemsArray) { //Console.WriteLine("New TreeItem"); foreach (BranchHistoryTreeItem treeItem in treeItems) { //Console.WriteLine("Relative: " + treeItem.Relative); //Console.WriteLine(treeItem.Relative.ServerItem); foreach (Object obj in treeItem.Children) { BranchRelative branch = obj as BranchRelative; Item fromItem = branch.BranchFromItem; Console.WriteLine(fromItem.ServerItem); Item toItem = branch.BranchToItem; Console.Write(">> \t" + toItem.ServerItem); Console.WriteLine("\tBranched from version " + fromItem.ChangesetId + " <<"); } } } }
public void UnmapWorkfolder(Workspace workspace, string item) { if (!VersionControlPath.IsServerItem(item)) { item = Path.GetFullPath(item); } List <WorkingFolder> folders = new List <WorkingFolder>(workspace.Folders); string msg = String.Empty; for (int i = 0; i < folders.Count; ++i) { WorkingFolder folder = folders[i]; if (item == folder.ServerItem || item == folder.LocalItem) { msg = String.Format("Removed: {0} => {1}", folder.ServerItem, folder.LocalItem); folders.RemoveAt(i); break; } } workspace.Update(workspace.Name, workspace.Comment, folders.ToArray()); if (!String.IsNullOrEmpty(msg)) { Console.WriteLine(msg); } }
/// <summary> /// Resolves the provided script parameter to either a server stored /// PS file or an inline script for direct execution. /// </summary> /// <param name="context">The activity context</param> /// <returns>An executable powershell script</returns> internal string ResolveScript(CodeActivityContext context) { var script = this.Script.Get(context); if (string.IsNullOrWhiteSpace(script)) { throw new ArgumentNullException("context", "Script"); } if (VersionControlPath.IsServerItem(script)) { var workspace = this.BuildWorkspace.Get(context); if (workspace == null) { throw new ArgumentNullException("context", "BuildWorkspace"); } var workspaceFilePath = workspace.GetLocalItemForServerItem(script); if (!File.Exists(workspaceFilePath)) { throw new FileNotFoundException("Script", string.Format(CultureInfo.CurrentCulture, "Workspace local path {0} for source path {1} was not found", script, workspaceFilePath)); } var arguments = this.Arguments.Get(context); script = "& '" + workspaceFilePath + "' " + arguments; } return(script); }
public static string GetRepositoryUrl(string path) { string text = null; if (!VersionControlPath.IsServerItem(path)) { try { text = GetWorkspace(path)?.ServerUri?.AbsoluteUri; } catch (ApplicationException) { } } return(text); }
/// <summary> /// Gets a file name. If the file references a file in source control a temporary file /// is created by download the content. Repeated calls to the same file will allways return /// the same temporary file (the file will not be download again from source control). /// The temporary file will be deleted when the instance of the class is disposed. Non source /// control files will be left untouched /// </summary> /// <param name="filePath">The path to track. May be a file from source control in the format $/project/path/filename.txt or /// a file in the filesystem.</param> /// <returns>the filename of the file. The filename itself if it's a file in the filesystem or a reference to the temporary file if a file is in source control</returns> public string GetFile(string filePath) { if (VersionControlPath.IsServerItem(filePath)) { if (this.trackedFiles.ContainsKey(filePath)) { return(this.trackedFiles[filePath]); } return(this.trackedFiles[filePath] = this.DownloadToTemporaryFile(filePath)); } return(filePath); }
private static WorkspaceInfo GetWorkspace(string path) { if (path != null) { try { if (!VersionControlPath.IsServerItem(path) && Workstation.Current.IsMapped(path)) { return(Workstation.Current.GetLocalWorkspaceInfo(path)); } } catch (Microsoft.TeamFoundation.InvalidPathException) { } } return(null); }
private void GetPathAndScope(string szFile, out VersionControlServer sourceControl, out Workspace workspace) { // Figure out the server based on either the argument or the // current directory. WorkspaceInfo wsInfo = null; workspace = null; if (!VersionControlPath.IsServerItem(szFile)) { wsInfo = Workstation.Current.GetLocalWorkspaceInfo(szFile); } TeamFoundationServer tfs = null; if (wsInfo == null) { wsInfo = Workstation.Current.GetLocalWorkspaceInfo(Environment.CurrentDirectory); } if (wsInfo != null) { //Just in case our local file is hooked to a different server m_szServerAddress = wsInfo.ServerUri.AbsoluteUri; } tfs = TeamFoundationServerFactory.GetServer(m_szServerAddress); sourceControl = (VersionControlServer)tfs.GetService(typeof(VersionControlServer)); // Pick up the label scope, if supplied. string scope = VersionControlPath.RootFolder; // The scope must be a server path, so we convert it here if // the user specified a local path. if (!VersionControlPath.IsServerItem(szFile)) { workspace = wsInfo.GetWorkspace(tfs); scope = workspace.GetServerItemForLocalItem(szFile); } else { scope = szFile; } }
protected override void InternalExecute() { var auth = this.Authentication.Get(this.ActivityContext); if (auth.AuthType == SSHAuthenticationType.PrivateKey) { auth.PrivateKeyFileLocation = auth.Key; if (VersionControlPath.IsServerItem(auth.Key)) { var vcs = this.ActivityContext.GetExtension <TfsTeamProjectCollection>().GetService <VersionControlServer>(); auth.PrivateKeyFileLocation = Path.GetTempFileName(); vcs.DownloadFile(auth.Key, auth.PrivateKeyFileLocation); } } }
public override void Run() { string sourcePath = String.Empty; string targetPath = String.Empty; switch (Arguments.Length) { case 0: Console.WriteLine("Usage: tf merges [<source>] <destination>"); Environment.Exit((int)ExitCode.Failure); break; case 1: targetPath = Arguments[0]; break; case 2: sourcePath = Arguments[0]; targetPath = Arguments[1]; break; } if (!VersionControlPath.IsServerItem(targetPath)) { targetPath = Path.GetFullPath(targetPath); } RecursionType rtype = OptionRecursive ? RecursionType.Full : RecursionType.None; bool setting = Settings.Current.GetAsBool("Merges.Recursive"); if (setting) { rtype = RecursionType.Full; } ChangesetMerge[] merges = VersionControlServer.QueryMerges(sourcePath, null, targetPath, VersionSpec.Latest, null, null, rtype); BriefOutput(merges); }
internal XElement ToXml(XName element) { XElement result = new XElement(element); if (this.RecursionType != RecursionType.None) { result.Add(new XAttribute("recurse", RecursionType)); } if (this.DeletionId != 0) { result.Add(new XAttribute("did", DeletionId)); } if (VersionControlPath.IsServerItem(Item)) { result.Add(new XAttribute("item", Item)); } else { result.Add(new XAttribute("item", TfsPath.FromPlatformPath(Item))); } return(result); }
public override void Run() { Workspace workspace = GetWorkspaceFromCache(); // process command options DeletedState dstate = OptionDeleted ? DeletedState.Any : DeletedState.NonDeleted; RecursionType rtype = OptionRecursive ? RecursionType.Full : RecursionType.OneLevel; List <ItemSpec> itemSpecs = new List <ItemSpec>(); for (int i = 0; i < Arguments.Length; i++) { string path = Arguments[i]; if (!VersionControlPath.IsServerItem(path)) { path = Path.GetFullPath(path); } itemSpecs.Add(new ItemSpec(path, rtype)); } ExtendedItem[][] items = workspace.GetExtendedItems(itemSpecs.ToArray(), dstate, ItemType.Any); if (items.Length == 0) { Console.WriteLine("No items match " + Arguments[0]); Environment.Exit((int)ExitCode.Failure); } foreach (ExtendedItem[] itemArray in items) { foreach (ExtendedItem item in itemArray) { Console.WriteLine("Local information:"); Console.WriteLine(" Local path : " + item.LocalItem); Console.WriteLine(" Server path: " + item.TargetServerItem); Console.WriteLine(" Changeset : " + item.VersionLocal); Console.WriteLine(" Change : " + item.ChangeType.ToString().ToLower()); Console.WriteLine(" Type : " + item.ItemType.ToString().ToLower()); Console.WriteLine("Server information:"); Console.WriteLine(" Server path : " + item.SourceServerItem); Console.WriteLine(" Changeset : " + item.VersionLatest); Console.WriteLine(" Deletion Id : " + item.DeletionId); Console.WriteLine(" Lock : " + item.LockStatus.ToString().ToLower()); Console.WriteLine(" Lock Owner : " + item.LockOwner); Console.WriteLine(" Last Modified: Not Implemented"); Console.WriteLine(" Type : " + item.ItemType.ToString().ToLower()); Encoding encoding = Encoding.GetEncoding(item.Encoding); Console.WriteLine(" File type : " + encoding.HeaderName); long len = 0; if (!String.IsNullOrEmpty(item.LocalItem)) { FileInfo fi = new FileInfo(item.LocalItem); len = fi.Length; } Console.WriteLine(" Size : " + Convert.ToString(len)); } } }
protected override void InternalExecute() { var auth = this.Authentication.Get(this.ActivityContext); if (auth.AuthType == SSHAuthenticationType.PrivateKey && string.IsNullOrWhiteSpace(auth.PrivateKeyFileLocation) == false && VersionControlPath.IsServerItem(auth.Key)) { try { if (System.IO.File.Exists(auth.PrivateKeyFileLocation)) { System.IO.File.Delete(auth.PrivateKeyFileLocation); } } catch (FileNotFoundException) { this.LogBuildWarning(string.Format("Failed to delete file {0}", auth.PrivateKeyFileLocation)); } } }
/// <summary> /// Checks if the path is a valid file under source control /// </summary> /// <param name="path">Path to source control in for '$/aaa/file.cs'</param> /// <returns>True if file found</returns> public bool IsServerItem(string path) { return(VersionControlPath.IsServerItem(path)); }
private static void GetPathAndScope(String[] args, out String path, out String scope, out VersionControlServer sourceControl) { // This little app takes either no args or a file path and optionally a scope. if (args.Length > 2 || args.Length == 1 && args[0] == "/?") { Console.WriteLine("Usage: labelhist"); Console.WriteLine(" labelhist path [label scope]"); Console.WriteLine(); Console.WriteLine("With no arguments, all label names and comments are displayed."); Console.WriteLine("If a path is specified, only the labels containing that path"); Console.WriteLine("are displayed."); Console.WriteLine("If a scope is supplied, only labels at or below that scope will"); Console.WriteLine("will be displayed."); Console.WriteLine(); Console.WriteLine("Examples: labelhist c:\\projects\\secret\\notes.txt"); Console.WriteLine(" labelhist $/secret/notes.txt"); Console.WriteLine(" labelhist c:\\projects\\secret\\notes.txt $/secret"); Environment.Exit(1); } // Figure out the server based on either the argument or the // current directory. WorkspaceInfo wsInfo = null; if (args.Length < 1) { path = null; } else { path = args[0]; try { if (!VersionControlPath.IsServerItem(path)) { wsInfo = Workstation.Current.GetLocalWorkspaceInfo(path); } } catch (Exception e) { // The user provided a bad path argument. Console.Error.WriteLine(e.Message); Environment.Exit(1); } } TeamFoundationServer tfs = null; if (wsInfo == null) { wsInfo = Workstation.Current.GetLocalWorkspaceInfo(Environment.CurrentDirectory); } // Stop if we couldn't figure out the server. if (wsInfo == null) { //Console.Error.WriteLine("Unable to determine the server."); //Environment.Exit(1); //tfs = TeamFoundationServerFactory.GetServer("http://tfsappserver:8080"); tfs = TeamFoundationServerFactory.GetServer("http://tfs.radiantsystems.com:8080"); } else { tfs = TeamFoundationServerFactory.GetServer(wsInfo.ServerUri.AbsoluteUri); } // TeamFoundationServerFactory.GetServer(wsInfo.ServerName); // RTM: wsInfo.ServerUri.AbsoluteUri); sourceControl = (VersionControlServer)tfs.GetService(typeof(VersionControlServer)); // Pick up the label scope, if supplied. scope = VersionControlPath.RootFolder; if (args.Length == 2) { // The scope must be a server path, so we convert it here if // the user specified a local path. if (!VersionControlPath.IsServerItem(args[1])) { Workspace workspace = wsInfo.GetWorkspace(tfs); scope = workspace.GetServerItemForLocalItem(args[1]); } else { scope = args[1]; } } }
public override void Run() { bool defaultCwdSetting = Settings.Current.GetAsBool("History.DefaultToCwd"); string path = Environment.CurrentDirectory; if (Arguments.Length > 0) { path = Arguments[0]; } else if (!defaultCwdSetting) { Console.WriteLine("The history command takes exactly one item."); return; } if (!VersionControlPath.IsServerItem(path)) { path = Path.GetFullPath(path); } RecursionType rtype = OptionRecursive ? RecursionType.Full : RecursionType.None; bool histSetting = Settings.Current.GetAsBool("History.Recursive"); if (histSetting) { rtype = RecursionType.Full; } bool includeChanges = Settings.Current.GetAsBool("History.Detailed"); if (!String.IsNullOrEmpty(OptionFormat)) { includeChanges = OptionFormat.Equals("detailed", StringComparison.InvariantCultureIgnoreCase); } int stopAfter = Settings.Current.GetAsInt("History.StopAfter"); if (OptionStopAfter != -1) { stopAfter = OptionStopAfter; } VersionSpec version = VersionSpec.Latest; VersionSpec toVersion = null; VersionSpec fromVersion = null; if (!String.IsNullOrEmpty(OptionVersion)) { int tilda = OptionVersion.IndexOf("~"); if (tilda == -1) { version = VersionSpec.ParseSingleSpec(OptionVersion, Driver.Username); } else { string from = OptionVersion.Substring(0, tilda); if (!String.IsNullOrEmpty(from)) { fromVersion = VersionSpec.ParseSingleSpec(from, Driver.Username); } string to = OptionVersion.Substring(tilda + 1); if (!String.IsNullOrEmpty(to)) { toVersion = VersionSpec.ParseSingleSpec(to, Driver.Username); } } } IEnumerable changeSets = VersionControlServer.QueryHistory(path, version, 0, rtype, OptionUser, fromVersion, toVersion, stopAfter, includeChanges, false, false); if (OptionFormat.Equals("byowner", StringComparison.InvariantCultureIgnoreCase)) { ByOwnerOutput(changeSets, stopAfter); Environment.Exit((int)ExitCode.Success); } int maxId = "Changeset".Length, maxOwner = 5, maxDate = 6; foreach (Changeset changeSet in changeSets) { string id = Convert.ToString(changeSet.ChangesetId); if (id.Length > maxId) { maxId = id.Length; } string date = changeSet.CreationDate.ToString(OptionDateTimeFormat); if (date.Length > maxDate) { maxDate = date.Length; } string name = StripDomainPrefix(changeSet.Owner); int ownerNameLen = name.Length; if (ownerNameLen > maxOwner) { maxOwner = ownerNameLen; } } int maxComment = WindowWidth - maxId - maxOwner - maxDate - 5; string line = String.Format("{0} {1} {2} {3}", "Changeset".PadRight(maxId), "User".PadRight(maxOwner), "Date".PadRight(maxDate), "Comment".PadRight(maxComment)); Console.WriteLine(line); line = String.Format("{0} {1} {2} {3}", "-".PadRight(maxId, '-'), "-".PadRight(maxOwner, '-'), "-".PadRight(maxDate, '-'), "-".PadRight(maxComment, '-')); Console.WriteLine(line); foreach (Changeset changeSet in changeSets) { string comment = "none"; if (changeSet.Comment != null) { if (changeSet.Comment.Length > maxComment) { comment = changeSet.Comment.Remove(maxComment); } else { comment = changeSet.Comment; } } // domain is stripped on output string owner = StripDomainPrefix(changeSet.Owner); line = String.Format("{0} {1} {2} {3}", Convert.ToString(changeSet.ChangesetId).PadRight(maxId), owner.PadRight(maxOwner), changeSet.CreationDate.ToString(OptionDateTimeFormat).PadRight(maxDate), comment); Console.WriteLine(line); if (!includeChanges) { continue; } foreach (Change change in changeSet.Changes) { Console.WriteLine(" " + ChangeTypeToString(change.ChangeType) + " " + change.Item.ServerItem); } } }