diff --git a/GitTfs.VsCommon/TfsHelper.Common.cs b/GitTfs.VsCommon/TfsHelper.Common.cs index 8039da43..e9d140b3 100644 --- a/GitTfs.VsCommon/TfsHelper.Common.cs +++ b/GitTfs.VsCommon/TfsHelper.Common.cs @@ -574,9 +574,10 @@ namespace Sep.Git.Tfs.VsCommon return new WorkItemCheckedInfo(Convert.ToInt32(workitem), true, checkinAction); } - public IEnumerable GetLabels(string tfsPathBranch) + public IEnumerable GetLabels(string tfsPathBranch, string nameFilter = null) { - var labels = VersionControl.QueryLabels(null, tfsPathBranch, null, true, tfsPathBranch, VersionSpec.Latest); + var labels = VersionControl.QueryLabels(nameFilter, tfsPathBranch, null, true, tfsPathBranch, VersionSpec.Latest); + return labels.Select(e => new TfsLabel { Id = e.LabelId, Name = e.Name, diff --git a/GitTfs.VsFake/TfsHelper.VsFake.cs b/GitTfs.VsFake/TfsHelper.VsFake.cs index fdad681f..bb42c061 100644 --- a/GitTfs.VsFake/TfsHelper.VsFake.cs +++ b/GitTfs.VsFake/TfsHelper.VsFake.cs @@ -351,7 +351,7 @@ namespace Sep.Git.Tfs.VsFake throw new NotImplementedException(); } - public IEnumerable GetLabels(string tfsPathBranch) + public IEnumerable GetLabels(string tfsPathBranch, string nameFilter = null) { throw new NotImplementedException(); } diff --git a/GitTfs/Commands/Labels.cs b/GitTfs/Commands/Labels.cs index 2e39543d..b02f5025 100644 --- a/GitTfs/Commands/Labels.cs +++ b/GitTfs/Commands/Labels.cs @@ -3,6 +3,7 @@ using System.ComponentModel; using System.Diagnostics; using System.IO; using System.Linq; +using System.Text.RegularExpressions; using NDesk.Options; using Sep.Git.Tfs.Core; using StructureMap; @@ -24,6 +25,8 @@ namespace Sep.Git.Tfs.Commands public string TfsPassword { get; set; } public string ParentBranch { get; set; } public bool LabelAllBranches { get; set; } + public string NameFilter { get; set; } + public string ExcludeNameFilter { get; set; } string AuthorsFilePath { get; set; } public Labels(TextWriter stdout, Globals globals, AuthorsFile authors) @@ -40,6 +43,8 @@ namespace Sep.Git.Tfs.Commands return new OptionSet { { "all|fetch-all", "Fetch all the labels on all the TFS remotes (For TFS 2010 and later)", v => LabelAllBranches = v != null }, + { "n|label-name=", "Fetch all the labels respecting this name filter", v => NameFilter = v }, + { "e|exclude-label-name=", "Exclude all the labels respecting this regex name filter", v => ExcludeNameFilter = v }, { "u|username=", "TFS username", v => TfsUsername = v }, { "p|password=", "TFS password", v => TfsPassword = v }, { "a|authors=", "Path to an Authors file to map TFS users to Git users", v => AuthorsFilePath = v }, @@ -83,12 +88,25 @@ namespace Sep.Git.Tfs.Commands private int CreateLabelsForTfsBranch(IGitTfsRemote tfsRemote) { + if (string.IsNullOrWhiteSpace(NameFilter)) + NameFilter = null; + else + NameFilter = NameFilter.Trim(); + UpdateRemote(tfsRemote); _stdout.WriteLine("Looking for label on " + tfsRemote.TfsRepositoryPath + "..."); - var labels = tfsRemote.Tfs.GetLabels(tfsRemote.TfsRepositoryPath); + var labels = tfsRemote.Tfs.GetLabels(tfsRemote.TfsRepositoryPath, NameFilter); _stdout.WriteLine(labels.Count() +" labels found!"); + + Regex exludeRegex = null; + if (ExcludeNameFilter != null) + exludeRegex = new Regex(ExcludeNameFilter); + foreach (var label in labels) { + if (ExcludeNameFilter != null && exludeRegex.IsMatch(label.Name)) + continue; + Trace.WriteLine("LabelId:" + label.Id + "/ChangesetId:" + label.ChangesetId + "/LabelName:" + label.Name + "/Owner:" + label.Owner); Trace.WriteLine("Try to find changeset in git repository..."); string sha1TagCommit = _globals.Repository.FindCommitHashByCommitMessage("git-tfs-id: .*;C" + label.ChangesetId + "[^0-9]"); diff --git a/GitTfs/Core/TfsInterop/ITfsHelper.cs b/GitTfs/Core/TfsInterop/ITfsHelper.cs index bd0eb076..a5be1b53 100644 --- a/GitTfs/Core/TfsInterop/ITfsHelper.cs +++ b/GitTfs/Core/TfsInterop/ITfsHelper.cs @@ -28,9 +28,9 @@ namespace Sep.Git.Tfs.Core.TfsInterop long ShowCheckinDialog(IWorkspace workspace, IPendingChange[] pendingChanges, IEnumerable checkedInfos, string checkinComment); void CleanupWorkspaces(string workingDirectory); int GetRootChangesetForBranch(string tfsPathBranchToCreate, string tfsPathParentBranch = null); - IEnumerable GetLabels(string tfsPathBranch); + IEnumerable GetLabels(string tfsPathBranch, string nameFilter = null); bool CanGetBranchInformation { get; } IEnumerable GetAllTfsBranchesOrderedByCreation(); void EnsureAuthenticated(); } -} \ No newline at end of file +}