From 0de022a07a2d0d16090759248c47eb395b7cc0fb Mon Sep 17 00:00:00 2001 From: "Joel W. Reed" Date: Thu, 16 Aug 2007 13:44:04 -0400 Subject: [PATCH] tf add /others --- ChangeLog | 3 ++- tools/tf/AddCommand.cs | 56 +++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 55 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7426552..c795ada 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,7 +3,8 @@ * v0.5.1 release notes # NEW: add "explore" command for visually browsing a repository - # NEW: Support wildcards in checkout paths + # NEW: support for tf add /others + # NEW: support wildcards in checkout paths # BUGFIX: when deleting directories, delete any files within them automatically # BUGFIX: on windows, must do case insensitive path comparisons diff --git a/tools/tf/AddCommand.cs b/tools/tf/AddCommand.cs index f45731b..e5dd865 100644 --- a/tools/tf/AddCommand.cs +++ b/tools/tf/AddCommand.cs @@ -40,16 +40,66 @@ class AddCommand : Command [Option("Recursive", "R", "recursive")] public bool OptionRecursive = false; + [Option("Add other/unknown files", "", "others")] + public bool OptionOthers = false; + public AddCommand(Driver driver, string[] args): base(driver, args) { } - public override void Run() + public List AddOtherFiles(Workspace workspace, string[] args) { - ConfirmFilesSpecified(); + string path = Environment.CurrentDirectory; + if (args.Length > 0) + path = Path.GetFullPath(args[0]); + + char[] charsToTrim = { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar}; + string itemPath = path.TrimEnd(charsToTrim); + + workspace.RefreshMappings(); + string serverPath = workspace.GetServerItemForLocalItem(itemPath); + + ItemSpec itemSpec = new ItemSpec(itemPath, RecursionType.Full); + WorkspaceVersionSpec version = new WorkspaceVersionSpec(workspace); + + ItemSet itemSet = VersionControlServer.GetItems(itemSpec, version, DeletedState.NonDeleted, ItemType.File, true); + Item[] items = itemSet.Items; + + SortedList itemList = new SortedList(PathComparer); + + foreach (Item item in items) + { + if (item.ServerItem.Length == serverPath.Length) continue; + string serverItem = item.ServerItem.Remove(0, serverPath.Length+1); + string fname = Path.Combine(itemPath, serverItem); + itemList.Add(fname, true); + } - List paths = VerifiedFullPaths(Arguments); + List paths = new List(); + DirectoryInfo dir = new DirectoryInfo(itemPath); + + foreach (FileInfo file in dir.GetFiles("*", SearchOption.AllDirectories)) + { + if (itemList.ContainsKey(file.FullName)) continue; + Console.WriteLine("Adding " + file.FullName); + paths.Add(file.FullName); + } + + return paths; + } + + public override void Run() + { Workspace workspace = GetWorkspaceFromCache(); + List paths; + + if (OptionOthers) + paths = AddOtherFiles(workspace, Arguments); + else + { + ConfirmFilesSpecified(); + paths = VerifiedFullPaths(Arguments); + } int rc = workspace.PendAdd(paths.ToArray(), OptionRecursive); Console.WriteLine("{0} file(s) added.", rc); -- 2.11.4.GIT