From 7ef9fe888e03e2f898dc1f097c5098d9e75e9b5b Mon Sep 17 00:00:00 2001 From: Philippe Miossec Date: Tue, 8 Jan 2013 19:27:32 +0100 Subject: [PATCH 01/10] Add a new `list-remote-branches` command ... to help find root TFS paths to clone --- GitTfs/Commands/Branch.cs | 15 +++---- GitTfs/Commands/Clone.cs | 2 +- GitTfs/Commands/ListRemoteBranches.cs | 63 +++++++++++++++++++++++++++ GitTfs/Commands/QuickClone.cs | 4 +- GitTfs/GitTfs.csproj | 3 +- 5 files changed, 76 insertions(+), 11 deletions(-) create mode 100644 GitTfs/Commands/ListRemoteBranches.cs diff --git a/GitTfs/Commands/Branch.cs b/GitTfs/Commands/Branch.cs index f413906f1..d546f9ad8 100644 --- a/GitTfs/Commands/Branch.cs +++ b/GitTfs/Commands/Branch.cs @@ -43,7 +43,10 @@ public int Run() var tfsRemotes = globals.Repository.ReadAllTfsRemotes(); if (DisplayRemotes) { - WriteRemoteTfsBranchStructure(stdout, remoteId, tfsRemotes); + var remote = globals.Repository.ReadTfsRemote(remoteId); + + stdout.WriteLine("\nTFS branch structure:"); + WriteRemoteTfsBranchStructure(remote.Tfs, stdout, remote.TfsRepositoryPath, tfsRemotes); return GitTfsExitCodes.OK; } @@ -51,15 +54,11 @@ public int Run() return GitTfsExitCodes.OK; } - private void WriteRemoteTfsBranchStructure(TextWriter writer, string remoteId, IEnumerable tfsRemotes) + public static void WriteRemoteTfsBranchStructure(ITfsHelper tfsHelper, TextWriter writer, string tfsRepositoryPath, IEnumerable tfsRemotes = null) { - writer.WriteLine("\nTFS branch structure:"); - - var repo = globals.Repository; - var remote = repo.ReadTfsRemote(remoteId); - var root = remote.Tfs.GetRootTfsBranchForRemotePath(remote.TfsRepositoryPath); + var root = tfsHelper.GetRootTfsBranchForRemotePath(tfsRepositoryPath); - var visitor = new WriteBranchStructureTreeVisitor(remote.TfsRepositoryPath, writer, tfsRemotes); + var visitor = new WriteBranchStructureTreeVisitor(tfsRepositoryPath, writer, tfsRemotes); root.AcceptVisitor(visitor); } diff --git a/GitTfs/Commands/Clone.cs b/GitTfs/Commands/Clone.cs index cb42a2e43..435bfbd0e 100644 --- a/GitTfs/Commands/Clone.cs +++ b/GitTfs/Commands/Clone.cs @@ -13,7 +13,7 @@ namespace Sep.Git.Tfs.Commands { [Pluggable("clone")] - [Description("clone [options] tfs-url-or-instance-name repository-path ")] + [Description("clone [options] tfs-url-or-instance-name repository-path \n ex : git tfs clone http://myTfsServer:8080/tfs/TfsRepository $/ProjectName/ProjectBranch\n")] public class Clone : GitTfsCommand { private readonly Fetch fetch; diff --git a/GitTfs/Commands/ListRemoteBranches.cs b/GitTfs/Commands/ListRemoteBranches.cs new file mode 100644 index 000000000..bb31bdf57 --- /dev/null +++ b/GitTfs/Commands/ListRemoteBranches.cs @@ -0,0 +1,63 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.IO; +using System.Linq; +using NDesk.Options; +using Sep.Git.Tfs.Core; +using StructureMap; +using Sep.Git.Tfs.Util; +using Sep.Git.Tfs.Core.TfsInterop; + +namespace Sep.Git.Tfs.Commands +{ + [Pluggable("list-remote-branches")] + [Description("list-remote-branches tfs-url-or-instance-name \n git tfs list-remote-branches http://myTfsServer:8080/tfs/TfsRepository\n")] + public class ListRemoteBranches : GitTfsCommand + { + private readonly Globals globals; + private readonly ITfsHelper tfsHelper; + private readonly RemoteOptions remoteOptions; + private TextWriter stdout; + + public ListRemoteBranches(Globals globals, TextWriter stdout, ITfsHelper tfsHelper, RemoteOptions remoteOptions) + { + this.globals = globals; + this.stdout = stdout; + this.tfsHelper = tfsHelper; + this.remoteOptions = remoteOptions; + } + + public OptionSet OptionSet + { + get + { + return remoteOptions.OptionSet; + } + } + + public int Run(string tfsUrl) + { + if (!tfsHelper.CanGetBranchInformation) + { + throw new GitTfsException("error: this version of TFS doesn't support this functionnality"); + } + + tfsHelper.Url = tfsUrl; + tfsHelper.Username = remoteOptions.Username; + tfsHelper.Password = remoteOptions.Password; + tfsHelper.EnsureAuthenticated(); + var branches = tfsHelper.GetBranches().ToList(); + stdout.WriteLine("TFS branche(s) that could be cloned:\n"); + foreach (var branchObject in branches.Where(b => b.IsRoot)) + { + Branch.WriteRemoteTfsBranchStructure(tfsHelper, stdout, branchObject.Path); + stdout.WriteLine(string.Empty); + } + + stdout.WriteLine("\nCloning root branches (marked by [*]) are recommended!"); + return GitTfsExitCodes.OK; + } + } +} diff --git a/GitTfs/Commands/QuickClone.cs b/GitTfs/Commands/QuickClone.cs index a58d7cdff..79f1b5a54 100644 --- a/GitTfs/Commands/QuickClone.cs +++ b/GitTfs/Commands/QuickClone.cs @@ -1,4 +1,5 @@ using System.ComponentModel; +using System.IO; using StructureMap; namespace Sep.Git.Tfs.Commands @@ -7,7 +8,8 @@ namespace Sep.Git.Tfs.Commands [Description("quick-clone [options] tfs-url-or-instance-name repository-path ")] public class QuickClone : Clone { - public QuickClone(Globals globals, Init init, QuickFetch fetch) : base(globals, fetch, init, null, null) + public QuickClone(Globals globals, Init init, QuickFetch fetch, TextWriter stdout) + : base(globals, fetch, init, null, stdout) { } } diff --git a/GitTfs/GitTfs.csproj b/GitTfs/GitTfs.csproj index a22ed896e..d26c0e4e3 100644 --- a/GitTfs/GitTfs.csproj +++ b/GitTfs/GitTfs.csproj @@ -130,6 +130,7 @@ Properties\Version.cs + @@ -299,4 +300,4 @@ - + \ No newline at end of file From bbf10cca0b03ed6034f5ff4278dfbeac5e04e1d7 Mon Sep 17 00:00:00 2001 From: Thomas Wurtz Date: Sun, 20 Jan 2013 19:55:02 +0100 Subject: [PATCH 02/10] fix reading config for branches with dot in name --- GitTfs/Core/RemoteConfigConverter.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/GitTfs/Core/RemoteConfigConverter.cs b/GitTfs/Core/RemoteConfigConverter.cs index 1cf4a922f..6751fecbc 100644 --- a/GitTfs/Core/RemoteConfigConverter.cs +++ b/GitTfs/Core/RemoteConfigConverter.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using LibGit2Sharp; namespace Sep.Git.Tfs.Core @@ -14,8 +15,9 @@ public IEnumerable Load(IEnumerable config) var keyParts = entry.Key.Split('.'); if (keyParts.Length == 3 && keyParts[0] == "tfs-remote") { - var id = keyParts[1]; - var key = keyParts[2]; + // The branch name may contain dots ("maint-1.0.0") which must be considered since split on "." + var id = string.Join(".", keyParts, 1, keyParts.Length - 2); + var key = keyParts.Last(); var remote = remotes.GetOrAdd(id); remote.Id = id; if (key == "url") From 64e17b536feeed0e9a2dc8293d373b543dd14f45 Mon Sep 17 00:00:00 2001 From: Thomas Wurtz Date: Thu, 24 Jan 2013 00:58:52 +0100 Subject: [PATCH 03/10] Added missing check for greater than or equals. --- GitTfs/Core/RemoteConfigConverter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/GitTfs/Core/RemoteConfigConverter.cs b/GitTfs/Core/RemoteConfigConverter.cs index 6751fecbc..6986a1b24 100644 --- a/GitTfs/Core/RemoteConfigConverter.cs +++ b/GitTfs/Core/RemoteConfigConverter.cs @@ -13,7 +13,7 @@ public IEnumerable Load(IEnumerable config) foreach (var entry in config) { var keyParts = entry.Key.Split('.'); - if (keyParts.Length == 3 && keyParts[0] == "tfs-remote") + if (keyParts.Length >= 3 && keyParts[0] == "tfs-remote") { // The branch name may contain dots ("maint-1.0.0") which must be considered since split on "." var id = string.Join(".", keyParts, 1, keyParts.Length - 2); From dfab91cd41fb42ffa3d22b4a92e1d3760efc2b39 Mon Sep 17 00:00:00 2001 From: Thomas Wurtz Date: Sun, 27 Jan 2013 17:29:34 +0100 Subject: [PATCH 04/10] Added unittest to verify reading configuration for branches with dot in branch name --- .../Core/RemoteConfigConverterDumpTests.cs | 72 ++++++++++++++----- .../Core/RemoteConfigConverterLoadTests.cs | 70 ++++++++++++------ 2 files changed, 105 insertions(+), 37 deletions(-) diff --git a/GitTfsTest/Core/RemoteConfigConverterDumpTests.cs b/GitTfsTest/Core/RemoteConfigConverterDumpTests.cs index ed3935b49..1ecf336c2 100644 --- a/GitTfsTest/Core/RemoteConfigConverterDumpTests.cs +++ b/GitTfsTest/Core/RemoteConfigConverterDumpTests.cs @@ -27,22 +27,18 @@ public void DumpsNothingWithBlankId() [Fact] public void DumpsMinimalRemote() { - var remote = new RemoteInfo { Id = "default", Url = "http://server/path", Repository = "$/Project" }; + var remoteId = "default"; + var remote = new RemoteInfo { Id = remoteId, Url = "http://server/path", Repository = "$/Project" }; var config = _dumper.Dump(remote); - AssertContainsConfig("tfs-remote.default.url", "http://server/path", config); - AssertContainsConfig("tfs-remote.default.repository", "$/Project", config); - AssertContainsConfig("tfs-remote.default.username", null, config); - AssertContainsConfig("tfs-remote.default.password", null, config); - AssertContainsConfig("tfs-remote.default.ignore-paths", null, config); - AssertContainsConfig("tfs-remote.default.legacy-urls", null, config); - AssertContainsConfig("tfs-remote.default.autotag", null, config); + VerifyMinimalRemote(remoteId, config); } [Fact] public void DumpsCompleteRemote() { + var remoteId = "default"; var remote = new RemoteInfo { - Id = "default", + Id = remoteId, Url = "http://server/path", Repository = "$/Project", Username = "user", @@ -52,13 +48,57 @@ public void DumpsCompleteRemote() Aliases = new string[] { "http://abc", "http://def" }, }; var config = _dumper.Dump(remote); - AssertContainsConfig("tfs-remote.default.url", "http://server/path", config); - AssertContainsConfig("tfs-remote.default.repository", "$/Project", config); - AssertContainsConfig("tfs-remote.default.username", "user", config); - AssertContainsConfig("tfs-remote.default.password", "pass", config); - AssertContainsConfig("tfs-remote.default.ignore-paths", "abc", config); - AssertContainsConfig("tfs-remote.default.legacy-urls", "http://abc,http://def", config); - AssertContainsConfig("tfs-remote.default.autotag", "true", config); + VerifyCompleteRemote(remoteId, config); + } + + [Fact] + public void DumpsMinimalRemoteWithDotInName() + { + var remoteId = "maint-1.0.0.0"; + var remote = new RemoteInfo { Id = remoteId, Url = "http://server/path", Repository = "$/Project" }; + var config = _dumper.Dump(remote); + VerifyMinimalRemote(remoteId, config); + } + + [Fact] + public void DumpsCompleteRemoteWithDotInName() + { + var remoteId = "maint-1.0.0.0"; + var remote = new RemoteInfo + { + Id = remoteId, + Url = "http://server/path", + Repository = "$/Project", + Username = "user", + Password = "pass", + IgnoreRegex = "abc", + Autotag = true, + Aliases = new string[] { "http://abc", "http://def" }, + }; + var config = _dumper.Dump(remote); + VerifyCompleteRemote(remoteId, config); + } + + private void VerifyMinimalRemote(string remoteId, IEnumerable config) + { + AssertContainsConfig("tfs-remote." + remoteId + ".url", "http://server/path", config); + AssertContainsConfig("tfs-remote." + remoteId + ".repository", "$/Project", config); + AssertContainsConfig("tfs-remote." + remoteId + ".username", null, config); + AssertContainsConfig("tfs-remote." + remoteId + ".password", null, config); + AssertContainsConfig("tfs-remote." + remoteId + ".ignore-paths", null, config); + AssertContainsConfig("tfs-remote." + remoteId + ".legacy-urls", null, config); + AssertContainsConfig("tfs-remote." + remoteId + ".autotag", null, config); + } + + private void VerifyCompleteRemote(string remoteId, IEnumerable config) + { + AssertContainsConfig("tfs-remote." + remoteId + ".url", "http://server/path", config); + AssertContainsConfig("tfs-remote." + remoteId + ".repository", "$/Project", config); + AssertContainsConfig("tfs-remote." + remoteId + ".username", "user", config); + AssertContainsConfig("tfs-remote." + remoteId + ".password", "pass", config); + AssertContainsConfig("tfs-remote." + remoteId + ".ignore-paths", "abc", config); + AssertContainsConfig("tfs-remote." + remoteId + ".legacy-urls", "http://abc,http://def", config); + AssertContainsConfig("tfs-remote." + remoteId + ".autotag", "true", config); } private void AssertContainsConfig(string key, string value, IEnumerable configs) diff --git a/GitTfsTest/Core/RemoteConfigConverterLoadTests.cs b/GitTfsTest/Core/RemoteConfigConverterLoadTests.cs index 7c1456632..8b2da9722 100644 --- a/GitTfsTest/Core/RemoteConfigConverterLoadTests.cs +++ b/GitTfsTest/Core/RemoteConfigConverterLoadTests.cs @@ -29,40 +29,57 @@ public void NoConfig() Assert.Empty(_remotes); } - void SetUpMinimalRemote() + private void SetUpMinimalRemote(string remoteId) { - _config["tfs-remote.default.url"] = "http://server/path"; - _config["tfs-remote.default.repository"] = "$/project"; + _config["tfs-remote." + remoteId + ".url"] = "http://server/path"; + _config["tfs-remote." + remoteId + ".repository"] = "$/project"; } [Fact] public void MinimalRemote() { - SetUpMinimalRemote(); - Assert.Equal(1, _remotes.Count()); - Assert.Equal("default", _firstRemote.Id); - Assert.Equal("http://server/path", _firstRemote.Url); - Assert.Equal("$/project", _firstRemote.Repository); - Assert.Null(_firstRemote.Username); - Assert.Null(_firstRemote.Password); - Assert.Null(_firstRemote.IgnoreRegex); + var remoteId = "default"; + SetUpMinimalRemote(remoteId); + VerifyMinimalRemote(remoteId); + } + + private void SetUpCompleteRemote(string remoteId) + { + SetUpMinimalRemote(remoteId); + _config["tfs-remote." + remoteId + ".username"] = "theuser"; + _config["tfs-remote." + remoteId + ".password"] = "thepassword"; + _config["tfs-remote." + remoteId + ".ignore-paths"] = "ignorethis.zip"; + _config["tfs-remote." + remoteId + ".legacy-urls"] = "http://old:8080/,http://other/"; + _config["tfs-remote." + remoteId + ".autotag"] = "true"; + } + + [Fact] + public void CompleteRemote() + { + var remoteId = "default"; + SetUpCompleteRemote(remoteId); + VerifyCompleteRemote(remoteId); } - void SetUpCompleteRemote() + [Fact] + public void MinimalRemoteWithDotInName() { - SetUpMinimalRemote(); - _config["tfs-remote.default.username"] = "theuser"; - _config["tfs-remote.default.password"] = "thepassword"; - _config["tfs-remote.default.ignore-paths"] = "ignorethis.zip"; - _config["tfs-remote.default.legacy-urls"] = "http://old:8080/,http://other/"; - _config["tfs-remote.default.autotag"] = "true"; + var remoteId = "maint-1.0.0.0"; + SetUpCompleteRemote(remoteId); + VerifyCompleteRemote(remoteId); } [Fact] - public void RemoteWithEverything() + public void CompleteRemoteWithDotInName() + { + var remoteId = "maint-1.0.0.0"; + SetUpCompleteRemote(remoteId); + VerifyCompleteRemote(remoteId); + } + + private void VerifyCompleteRemote(string remoteId) { - SetUpCompleteRemote(); - Assert.Equal("default", _firstRemote.Id); + Assert.Equal(remoteId, _firstRemote.Id); Assert.Equal("http://server/path", _firstRemote.Url); Assert.Equal("$/project", _firstRemote.Repository); Assert.Equal("theuser", _firstRemote.Username); @@ -71,5 +88,16 @@ public void RemoteWithEverything() Assert.Equal(new string[] { "http://old:8080/", "http://other/" }, _firstRemote.Aliases); Assert.True(_firstRemote.Autotag); } + + private void VerifyMinimalRemote(string remoteId) + { + Assert.Equal(1, _remotes.Count()); + Assert.Equal(remoteId, _firstRemote.Id); + Assert.Equal("http://server/path", _firstRemote.Url); + Assert.Equal("$/project", _firstRemote.Repository); + Assert.Null(_firstRemote.Username); + Assert.Null(_firstRemote.Password); + Assert.Null(_firstRemote.IgnoreRegex); + } } } From 88a55766d33b175cf699c5e0ffc413e1cbf25f13 Mon Sep 17 00:00:00 2001 From: Matt Burke Date: Mon, 28 Jan 2013 07:56:53 -0500 Subject: [PATCH 05/10] Move the remotes-with-dots test to a different place. --- .../Core/RemoteConfigConverterDumpTests.cs | 72 +++++-------------- .../Core/RemoteConfigConverterLoadTests.cs | 70 ++++++------------ GitTfsTest/Core/RemoteConfigConverterTests.cs | 23 ++++++ GitTfsTest/GitTfsTest.csproj | 1 + 4 files changed, 61 insertions(+), 105 deletions(-) create mode 100644 GitTfsTest/Core/RemoteConfigConverterTests.cs diff --git a/GitTfsTest/Core/RemoteConfigConverterDumpTests.cs b/GitTfsTest/Core/RemoteConfigConverterDumpTests.cs index 1ecf336c2..ed3935b49 100644 --- a/GitTfsTest/Core/RemoteConfigConverterDumpTests.cs +++ b/GitTfsTest/Core/RemoteConfigConverterDumpTests.cs @@ -27,18 +27,22 @@ public void DumpsNothingWithBlankId() [Fact] public void DumpsMinimalRemote() { - var remoteId = "default"; - var remote = new RemoteInfo { Id = remoteId, Url = "http://server/path", Repository = "$/Project" }; + var remote = new RemoteInfo { Id = "default", Url = "http://server/path", Repository = "$/Project" }; var config = _dumper.Dump(remote); - VerifyMinimalRemote(remoteId, config); + AssertContainsConfig("tfs-remote.default.url", "http://server/path", config); + AssertContainsConfig("tfs-remote.default.repository", "$/Project", config); + AssertContainsConfig("tfs-remote.default.username", null, config); + AssertContainsConfig("tfs-remote.default.password", null, config); + AssertContainsConfig("tfs-remote.default.ignore-paths", null, config); + AssertContainsConfig("tfs-remote.default.legacy-urls", null, config); + AssertContainsConfig("tfs-remote.default.autotag", null, config); } [Fact] public void DumpsCompleteRemote() { - var remoteId = "default"; var remote = new RemoteInfo { - Id = remoteId, + Id = "default", Url = "http://server/path", Repository = "$/Project", Username = "user", @@ -48,57 +52,13 @@ public void DumpsCompleteRemote() Aliases = new string[] { "http://abc", "http://def" }, }; var config = _dumper.Dump(remote); - VerifyCompleteRemote(remoteId, config); - } - - [Fact] - public void DumpsMinimalRemoteWithDotInName() - { - var remoteId = "maint-1.0.0.0"; - var remote = new RemoteInfo { Id = remoteId, Url = "http://server/path", Repository = "$/Project" }; - var config = _dumper.Dump(remote); - VerifyMinimalRemote(remoteId, config); - } - - [Fact] - public void DumpsCompleteRemoteWithDotInName() - { - var remoteId = "maint-1.0.0.0"; - var remote = new RemoteInfo - { - Id = remoteId, - Url = "http://server/path", - Repository = "$/Project", - Username = "user", - Password = "pass", - IgnoreRegex = "abc", - Autotag = true, - Aliases = new string[] { "http://abc", "http://def" }, - }; - var config = _dumper.Dump(remote); - VerifyCompleteRemote(remoteId, config); - } - - private void VerifyMinimalRemote(string remoteId, IEnumerable config) - { - AssertContainsConfig("tfs-remote." + remoteId + ".url", "http://server/path", config); - AssertContainsConfig("tfs-remote." + remoteId + ".repository", "$/Project", config); - AssertContainsConfig("tfs-remote." + remoteId + ".username", null, config); - AssertContainsConfig("tfs-remote." + remoteId + ".password", null, config); - AssertContainsConfig("tfs-remote." + remoteId + ".ignore-paths", null, config); - AssertContainsConfig("tfs-remote." + remoteId + ".legacy-urls", null, config); - AssertContainsConfig("tfs-remote." + remoteId + ".autotag", null, config); - } - - private void VerifyCompleteRemote(string remoteId, IEnumerable config) - { - AssertContainsConfig("tfs-remote." + remoteId + ".url", "http://server/path", config); - AssertContainsConfig("tfs-remote." + remoteId + ".repository", "$/Project", config); - AssertContainsConfig("tfs-remote." + remoteId + ".username", "user", config); - AssertContainsConfig("tfs-remote." + remoteId + ".password", "pass", config); - AssertContainsConfig("tfs-remote." + remoteId + ".ignore-paths", "abc", config); - AssertContainsConfig("tfs-remote." + remoteId + ".legacy-urls", "http://abc,http://def", config); - AssertContainsConfig("tfs-remote." + remoteId + ".autotag", "true", config); + AssertContainsConfig("tfs-remote.default.url", "http://server/path", config); + AssertContainsConfig("tfs-remote.default.repository", "$/Project", config); + AssertContainsConfig("tfs-remote.default.username", "user", config); + AssertContainsConfig("tfs-remote.default.password", "pass", config); + AssertContainsConfig("tfs-remote.default.ignore-paths", "abc", config); + AssertContainsConfig("tfs-remote.default.legacy-urls", "http://abc,http://def", config); + AssertContainsConfig("tfs-remote.default.autotag", "true", config); } private void AssertContainsConfig(string key, string value, IEnumerable configs) diff --git a/GitTfsTest/Core/RemoteConfigConverterLoadTests.cs b/GitTfsTest/Core/RemoteConfigConverterLoadTests.cs index 8b2da9722..7c1456632 100644 --- a/GitTfsTest/Core/RemoteConfigConverterLoadTests.cs +++ b/GitTfsTest/Core/RemoteConfigConverterLoadTests.cs @@ -29,57 +29,40 @@ public void NoConfig() Assert.Empty(_remotes); } - private void SetUpMinimalRemote(string remoteId) + void SetUpMinimalRemote() { - _config["tfs-remote." + remoteId + ".url"] = "http://server/path"; - _config["tfs-remote." + remoteId + ".repository"] = "$/project"; + _config["tfs-remote.default.url"] = "http://server/path"; + _config["tfs-remote.default.repository"] = "$/project"; } [Fact] public void MinimalRemote() { - var remoteId = "default"; - SetUpMinimalRemote(remoteId); - VerifyMinimalRemote(remoteId); - } - - private void SetUpCompleteRemote(string remoteId) - { - SetUpMinimalRemote(remoteId); - _config["tfs-remote." + remoteId + ".username"] = "theuser"; - _config["tfs-remote." + remoteId + ".password"] = "thepassword"; - _config["tfs-remote." + remoteId + ".ignore-paths"] = "ignorethis.zip"; - _config["tfs-remote." + remoteId + ".legacy-urls"] = "http://old:8080/,http://other/"; - _config["tfs-remote." + remoteId + ".autotag"] = "true"; - } - - [Fact] - public void CompleteRemote() - { - var remoteId = "default"; - SetUpCompleteRemote(remoteId); - VerifyCompleteRemote(remoteId); + SetUpMinimalRemote(); + Assert.Equal(1, _remotes.Count()); + Assert.Equal("default", _firstRemote.Id); + Assert.Equal("http://server/path", _firstRemote.Url); + Assert.Equal("$/project", _firstRemote.Repository); + Assert.Null(_firstRemote.Username); + Assert.Null(_firstRemote.Password); + Assert.Null(_firstRemote.IgnoreRegex); } - [Fact] - public void MinimalRemoteWithDotInName() + void SetUpCompleteRemote() { - var remoteId = "maint-1.0.0.0"; - SetUpCompleteRemote(remoteId); - VerifyCompleteRemote(remoteId); + SetUpMinimalRemote(); + _config["tfs-remote.default.username"] = "theuser"; + _config["tfs-remote.default.password"] = "thepassword"; + _config["tfs-remote.default.ignore-paths"] = "ignorethis.zip"; + _config["tfs-remote.default.legacy-urls"] = "http://old:8080/,http://other/"; + _config["tfs-remote.default.autotag"] = "true"; } [Fact] - public void CompleteRemoteWithDotInName() - { - var remoteId = "maint-1.0.0.0"; - SetUpCompleteRemote(remoteId); - VerifyCompleteRemote(remoteId); - } - - private void VerifyCompleteRemote(string remoteId) + public void RemoteWithEverything() { - Assert.Equal(remoteId, _firstRemote.Id); + SetUpCompleteRemote(); + Assert.Equal("default", _firstRemote.Id); Assert.Equal("http://server/path", _firstRemote.Url); Assert.Equal("$/project", _firstRemote.Repository); Assert.Equal("theuser", _firstRemote.Username); @@ -88,16 +71,5 @@ private void VerifyCompleteRemote(string remoteId) Assert.Equal(new string[] { "http://old:8080/", "http://other/" }, _firstRemote.Aliases); Assert.True(_firstRemote.Autotag); } - - private void VerifyMinimalRemote(string remoteId) - { - Assert.Equal(1, _remotes.Count()); - Assert.Equal(remoteId, _firstRemote.Id); - Assert.Equal("http://server/path", _firstRemote.Url); - Assert.Equal("$/project", _firstRemote.Repository); - Assert.Null(_firstRemote.Username); - Assert.Null(_firstRemote.Password); - Assert.Null(_firstRemote.IgnoreRegex); - } } } diff --git a/GitTfsTest/Core/RemoteConfigConverterTests.cs b/GitTfsTest/Core/RemoteConfigConverterTests.cs new file mode 100644 index 000000000..afcc8a256 --- /dev/null +++ b/GitTfsTest/Core/RemoteConfigConverterTests.cs @@ -0,0 +1,23 @@ +using System; +using System.Linq; +using Xunit; +using Sep.Git.Tfs.Core; + +namespace Sep.Git.Tfs.Test.Core +{ + public class RemoteConfigConverterTests + { + [Fact] + public void HandlesDotsInName() + { + var originalRemote = new RemoteInfo { Id = "has.dots.in.it", Url = "http://do/not/care", Repository = "$/do/not/care" }; + var converter = new RemoteConfigConverter(); + var config = converter.Dump(originalRemote); + foreach (var entry in config) + Assert.True(entry.Key.StartsWith("tfs-remote.has.dots.in.it."), entry.Key + " should start with tfs-remote.has.dots.in.it"); + var remotes = converter.Load(config.Where(e => e.Value != null)); + Assert.Equal(1, remotes.Count()); + Assert.Equal("has.dots.in.it", remotes.First().Id); + } + } +} diff --git a/GitTfsTest/GitTfsTest.csproj b/GitTfsTest/GitTfsTest.csproj index a4834c8f5..23bb12b14 100644 --- a/GitTfsTest/GitTfsTest.csproj +++ b/GitTfsTest/GitTfsTest.csproj @@ -112,6 +112,7 @@ + From f5f3debf1ea2deb734ed467e5defabc494cd619b Mon Sep 17 00:00:00 2001 From: Matt Burke Date: Mon, 28 Jan 2013 08:06:04 -0500 Subject: [PATCH 06/10] Merge all the RemoteConfigConverter test classes. --- .../Core/RemoteConfigConverterDumpTests.cs | 84 ---------- .../Core/RemoteConfigConverterLoadTests.cs | 75 --------- GitTfsTest/Core/RemoteConfigConverterTests.cs | 146 ++++++++++++++++++ GitTfsTest/GitTfsTest.csproj | 2 - 4 files changed, 146 insertions(+), 161 deletions(-) delete mode 100644 GitTfsTest/Core/RemoteConfigConverterDumpTests.cs delete mode 100644 GitTfsTest/Core/RemoteConfigConverterLoadTests.cs diff --git a/GitTfsTest/Core/RemoteConfigConverterDumpTests.cs b/GitTfsTest/Core/RemoteConfigConverterDumpTests.cs deleted file mode 100644 index ed3935b49..000000000 --- a/GitTfsTest/Core/RemoteConfigConverterDumpTests.cs +++ /dev/null @@ -1,84 +0,0 @@ -using System; -using System.Collections.Generic; -using LibGit2Sharp; -using Xunit; -using Sep.Git.Tfs.Core; - -namespace Sep.Git.Tfs.Test.Core -{ - public class RemoteConfigConverterDumpTests - { - RemoteConfigConverter _dumper = new RemoteConfigConverter(); - - [Fact] - public void DumpsNothingWithNoId() - { - var remote = new RemoteInfo { Url = "http://server/path", Repository = "$/Project" }; - Assert.Empty(_dumper.Dump(remote)); - } - - [Fact] - public void DumpsNothingWithBlankId() - { - var remote = new RemoteInfo { Id = " ", Url = "http://server/path", Repository = "$/Project" }; - Assert.Empty(_dumper.Dump(remote)); - } - - [Fact] - public void DumpsMinimalRemote() - { - var remote = new RemoteInfo { Id = "default", Url = "http://server/path", Repository = "$/Project" }; - var config = _dumper.Dump(remote); - AssertContainsConfig("tfs-remote.default.url", "http://server/path", config); - AssertContainsConfig("tfs-remote.default.repository", "$/Project", config); - AssertContainsConfig("tfs-remote.default.username", null, config); - AssertContainsConfig("tfs-remote.default.password", null, config); - AssertContainsConfig("tfs-remote.default.ignore-paths", null, config); - AssertContainsConfig("tfs-remote.default.legacy-urls", null, config); - AssertContainsConfig("tfs-remote.default.autotag", null, config); - } - - [Fact] - public void DumpsCompleteRemote() - { - var remote = new RemoteInfo { - Id = "default", - Url = "http://server/path", - Repository = "$/Project", - Username = "user", - Password = "pass", - IgnoreRegex = "abc", - Autotag = true, - Aliases = new string[] { "http://abc", "http://def" }, - }; - var config = _dumper.Dump(remote); - AssertContainsConfig("tfs-remote.default.url", "http://server/path", config); - AssertContainsConfig("tfs-remote.default.repository", "$/Project", config); - AssertContainsConfig("tfs-remote.default.username", "user", config); - AssertContainsConfig("tfs-remote.default.password", "pass", config); - AssertContainsConfig("tfs-remote.default.ignore-paths", "abc", config); - AssertContainsConfig("tfs-remote.default.legacy-urls", "http://abc,http://def", config); - AssertContainsConfig("tfs-remote.default.autotag", "true", config); - } - - private void AssertContainsConfig(string key, string value, IEnumerable configs) - { - Assert.Contains(new ConfigurationEntry(key, value, ConfigurationLevel.Local), configs, configComparer); - } - - static IEqualityComparer configComparer = new ConfigurationEntryComparer(); - - class ConfigurationEntryComparer : IEqualityComparer - { - bool IEqualityComparer.Equals(ConfigurationEntry x, ConfigurationEntry y) - { - return x.Key == y.Key && x.Value == y.Value; - } - - int IEqualityComparer.GetHashCode(ConfigurationEntry obj) - { - return obj.Key.GetHashCode(); - } - } - } -} diff --git a/GitTfsTest/Core/RemoteConfigConverterLoadTests.cs b/GitTfsTest/Core/RemoteConfigConverterLoadTests.cs deleted file mode 100644 index 7c1456632..000000000 --- a/GitTfsTest/Core/RemoteConfigConverterLoadTests.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using LibGit2Sharp; -using Sep.Git.Tfs.Core; -using Xunit; - -namespace Sep.Git.Tfs.Test.Core -{ - public class RemoteConfigConverterLoadTests - { - RemoteConfigConverter _reader = new RemoteConfigConverter(); - Dictionary _config = new Dictionary(); - - IEnumerable _gitConfig { get { return _config.Select(x => new ConfigurationEntry(x.Key, x.Value, ConfigurationLevel.Local)); } } - IEnumerable _remotes { get { return _reader.Load(_gitConfig); } } - RemoteInfo _firstRemote { get { return _remotes.FirstOrDefault(); } } - - public RemoteConfigConverterLoadTests() - { - // Set some normal-ish config params. This makes sure that there is no barfing on extra config entries. - _config["core.autocrlf"] = "true"; - _config["ui.color"] = "auto"; - } - - [Fact] - public void NoConfig() - { - Assert.Empty(_remotes); - } - - void SetUpMinimalRemote() - { - _config["tfs-remote.default.url"] = "http://server/path"; - _config["tfs-remote.default.repository"] = "$/project"; - } - - [Fact] - public void MinimalRemote() - { - SetUpMinimalRemote(); - Assert.Equal(1, _remotes.Count()); - Assert.Equal("default", _firstRemote.Id); - Assert.Equal("http://server/path", _firstRemote.Url); - Assert.Equal("$/project", _firstRemote.Repository); - Assert.Null(_firstRemote.Username); - Assert.Null(_firstRemote.Password); - Assert.Null(_firstRemote.IgnoreRegex); - } - - void SetUpCompleteRemote() - { - SetUpMinimalRemote(); - _config["tfs-remote.default.username"] = "theuser"; - _config["tfs-remote.default.password"] = "thepassword"; - _config["tfs-remote.default.ignore-paths"] = "ignorethis.zip"; - _config["tfs-remote.default.legacy-urls"] = "http://old:8080/,http://other/"; - _config["tfs-remote.default.autotag"] = "true"; - } - - [Fact] - public void RemoteWithEverything() - { - SetUpCompleteRemote(); - Assert.Equal("default", _firstRemote.Id); - Assert.Equal("http://server/path", _firstRemote.Url); - Assert.Equal("$/project", _firstRemote.Repository); - Assert.Equal("theuser", _firstRemote.Username); - Assert.Equal("thepassword", _firstRemote.Password); - Assert.Equal("ignorethis.zip", _firstRemote.IgnoreRegex); - Assert.Equal(new string[] { "http://old:8080/", "http://other/" }, _firstRemote.Aliases); - Assert.True(_firstRemote.Autotag); - } - } -} diff --git a/GitTfsTest/Core/RemoteConfigConverterTests.cs b/GitTfsTest/Core/RemoteConfigConverterTests.cs index afcc8a256..912dfb26b 100644 --- a/GitTfsTest/Core/RemoteConfigConverterTests.cs +++ b/GitTfsTest/Core/RemoteConfigConverterTests.cs @@ -1,12 +1,158 @@ using System; +using System.Collections.Generic; using System.Linq; using Xunit; using Sep.Git.Tfs.Core; +using LibGit2Sharp; namespace Sep.Git.Tfs.Test.Core { public class RemoteConfigConverterTests { + public class DumpTests + { + RemoteConfigConverter _dumper = new RemoteConfigConverter(); + + [Fact] + public void DumpsNothingWithNoId() + { + var remote = new RemoteInfo { Url = "http://server/path", Repository = "$/Project" }; + Assert.Empty(_dumper.Dump(remote)); + } + + [Fact] + public void DumpsNothingWithBlankId() + { + var remote = new RemoteInfo { Id = " ", Url = "http://server/path", Repository = "$/Project" }; + Assert.Empty(_dumper.Dump(remote)); + } + + [Fact] + public void DumpsMinimalRemote() + { + var remote = new RemoteInfo { Id = "default", Url = "http://server/path", Repository = "$/Project" }; + var config = _dumper.Dump(remote); + AssertContainsConfig("tfs-remote.default.url", "http://server/path", config); + AssertContainsConfig("tfs-remote.default.repository", "$/Project", config); + AssertContainsConfig("tfs-remote.default.username", null, config); + AssertContainsConfig("tfs-remote.default.password", null, config); + AssertContainsConfig("tfs-remote.default.ignore-paths", null, config); + AssertContainsConfig("tfs-remote.default.legacy-urls", null, config); + AssertContainsConfig("tfs-remote.default.autotag", null, config); + } + + [Fact] + public void DumpsCompleteRemote() + { + var remote = new RemoteInfo + { + Id = "default", + Url = "http://server/path", + Repository = "$/Project", + Username = "user", + Password = "pass", + IgnoreRegex = "abc", + Autotag = true, + Aliases = new string[] { "http://abc", "http://def" }, + }; + var config = _dumper.Dump(remote); + AssertContainsConfig("tfs-remote.default.url", "http://server/path", config); + AssertContainsConfig("tfs-remote.default.repository", "$/Project", config); + AssertContainsConfig("tfs-remote.default.username", "user", config); + AssertContainsConfig("tfs-remote.default.password", "pass", config); + AssertContainsConfig("tfs-remote.default.ignore-paths", "abc", config); + AssertContainsConfig("tfs-remote.default.legacy-urls", "http://abc,http://def", config); + AssertContainsConfig("tfs-remote.default.autotag", "true", config); + } + + private void AssertContainsConfig(string key, string value, IEnumerable configs) + { + Assert.Contains(new ConfigurationEntry(key, value, ConfigurationLevel.Local), configs, configComparer); + } + + static IEqualityComparer configComparer = new ConfigurationEntryComparer(); + + class ConfigurationEntryComparer : IEqualityComparer + { + bool IEqualityComparer.Equals(ConfigurationEntry x, ConfigurationEntry y) + { + return x.Key == y.Key && x.Value == y.Value; + } + + int IEqualityComparer.GetHashCode(ConfigurationEntry obj) + { + return obj.Key.GetHashCode(); + } + } + } + + public class LoadTests + { + RemoteConfigConverter _reader = new RemoteConfigConverter(); + Dictionary _config = new Dictionary(); + + IEnumerable _gitConfig { get { return _config.Select(x => new ConfigurationEntry(x.Key, x.Value, ConfigurationLevel.Local)); } } + IEnumerable _remotes { get { return _reader.Load(_gitConfig); } } + RemoteInfo _firstRemote { get { return _remotes.FirstOrDefault(); } } + + public LoadTests() + { + // Set some normal-ish config params. This makes sure that there is no barfing on extra config entries. + _config["core.autocrlf"] = "true"; + _config["ui.color"] = "auto"; + } + + [Fact] + public void NoConfig() + { + Assert.Empty(_remotes); + } + + void SetUpMinimalRemote() + { + _config["tfs-remote.default.url"] = "http://server/path"; + _config["tfs-remote.default.repository"] = "$/project"; + } + + [Fact] + public void MinimalRemote() + { + SetUpMinimalRemote(); + Assert.Equal(1, _remotes.Count()); + Assert.Equal("default", _firstRemote.Id); + Assert.Equal("http://server/path", _firstRemote.Url); + Assert.Equal("$/project", _firstRemote.Repository); + Assert.Null(_firstRemote.Username); + Assert.Null(_firstRemote.Password); + Assert.Null(_firstRemote.IgnoreRegex); + } + + void SetUpCompleteRemote() + { + SetUpMinimalRemote(); + _config["tfs-remote.default.username"] = "theuser"; + _config["tfs-remote.default.password"] = "thepassword"; + _config["tfs-remote.default.ignore-paths"] = "ignorethis.zip"; + _config["tfs-remote.default.legacy-urls"] = "http://old:8080/,http://other/"; + _config["tfs-remote.default.autotag"] = "true"; + } + + [Fact] + public void RemoteWithEverything() + { + SetUpCompleteRemote(); + Assert.Equal("default", _firstRemote.Id); + Assert.Equal("http://server/path", _firstRemote.Url); + Assert.Equal("$/project", _firstRemote.Repository); + Assert.Equal("theuser", _firstRemote.Username); + Assert.Equal("thepassword", _firstRemote.Password); + Assert.Equal("ignorethis.zip", _firstRemote.IgnoreRegex); + Assert.Equal(new string[] { "http://old:8080/", "http://other/" }, _firstRemote.Aliases); + Assert.True(_firstRemote.Autotag); + } + } + + [Fact] public void HandlesDotsInName() { diff --git a/GitTfsTest/GitTfsTest.csproj b/GitTfsTest/GitTfsTest.csproj index 23bb12b14..aa5cfd972 100644 --- a/GitTfsTest/GitTfsTest.csproj +++ b/GitTfsTest/GitTfsTest.csproj @@ -120,8 +120,6 @@ - - From f7400ffccf37beb8172e58e0ed0da2f89f9c32f8 Mon Sep 17 00:00:00 2001 From: Matt Burke Date: Mon, 28 Jan 2013 08:24:15 -0500 Subject: [PATCH 07/10] Refactor, and add a missing test. --- GitTfsTest/Core/RemoteConfigConverterTests.cs | 107 +++++++++++------- 1 file changed, 63 insertions(+), 44 deletions(-) diff --git a/GitTfsTest/Core/RemoteConfigConverterTests.cs b/GitTfsTest/Core/RemoteConfigConverterTests.cs index 912dfb26b..97603a1ec 100644 --- a/GitTfsTest/Core/RemoteConfigConverterTests.cs +++ b/GitTfsTest/Core/RemoteConfigConverterTests.cs @@ -88,80 +88,99 @@ int IEqualityComparer.GetHashCode(ConfigurationEntry obj) public class LoadTests { - RemoteConfigConverter _reader = new RemoteConfigConverter(); - Dictionary _config = new Dictionary(); + RemoteConfigConverter _loader = new RemoteConfigConverter(); - IEnumerable _gitConfig { get { return _config.Select(x => new ConfigurationEntry(x.Key, x.Value, ConfigurationLevel.Local)); } } - IEnumerable _remotes { get { return _reader.Load(_gitConfig); } } - RemoteInfo _firstRemote { get { return _remotes.FirstOrDefault(); } } + private IEnumerable Load(params ConfigurationEntry[] configs) + { + return _loader.Load(configs); + } - public LoadTests() + private ConfigurationEntry c(string key, string value) { - // Set some normal-ish config params. This makes sure that there is no barfing on extra config entries. - _config["core.autocrlf"] = "true"; - _config["ui.color"] = "auto"; + return new ConfigurationEntry(key, value, ConfigurationLevel.Local); } [Fact] public void NoConfig() { - Assert.Empty(_remotes); + var remotes = _loader.Load(Enumerable.Empty()); + Assert.Empty(remotes); } - void SetUpMinimalRemote() + [Fact] + public void OnlyGitConfig() { - _config["tfs-remote.default.url"] = "http://server/path"; - _config["tfs-remote.default.repository"] = "$/project"; + var remotes = Load( + c("core.autocrlf", "true"), + c("ui.color", "true")); + Assert.Empty(remotes); } [Fact] public void MinimalRemote() { - SetUpMinimalRemote(); - Assert.Equal(1, _remotes.Count()); - Assert.Equal("default", _firstRemote.Id); - Assert.Equal("http://server/path", _firstRemote.Url); - Assert.Equal("$/project", _firstRemote.Repository); - Assert.Null(_firstRemote.Username); - Assert.Null(_firstRemote.Password); - Assert.Null(_firstRemote.IgnoreRegex); - } - - void SetUpCompleteRemote() - { - SetUpMinimalRemote(); - _config["tfs-remote.default.username"] = "theuser"; - _config["tfs-remote.default.password"] = "thepassword"; - _config["tfs-remote.default.ignore-paths"] = "ignorethis.zip"; - _config["tfs-remote.default.legacy-urls"] = "http://old:8080/,http://other/"; - _config["tfs-remote.default.autotag"] = "true"; + var remotes = Load( + c("tfs-remote.default.url", "http://server/path"), + c("tfs-remote.default.repository", "$/project")); + Assert.Equal(1, remotes.Count()); + var remote = remotes.First(); + Assert.Equal("default", remote.Id); + Assert.Equal("http://server/path", remote.Url); + Assert.Equal("$/project", remote.Repository); + Assert.Null(remote.Username); + Assert.Null(remote.Password); + Assert.Null(remote.IgnoreRegex); } [Fact] public void RemoteWithEverything() { - SetUpCompleteRemote(); - Assert.Equal("default", _firstRemote.Id); - Assert.Equal("http://server/path", _firstRemote.Url); - Assert.Equal("$/project", _firstRemote.Repository); - Assert.Equal("theuser", _firstRemote.Username); - Assert.Equal("thepassword", _firstRemote.Password); - Assert.Equal("ignorethis.zip", _firstRemote.IgnoreRegex); - Assert.Equal(new string[] { "http://old:8080/", "http://other/" }, _firstRemote.Aliases); - Assert.True(_firstRemote.Autotag); + var remotes = Load( + c("tfs-remote.default.url", "http://server/path"), + c("tfs-remote.default.repository", "$/project"), + c("tfs-remote.default.username", "theuser"), + c("tfs-remote.default.password", "thepassword"), + c("tfs-remote.default.ignore-paths", "ignorethis.zip"), + c("tfs-remote.default.legacy-urls", "http://old:8080/,http://other/"), + c("tfs-remote.default.autotag", "true")); + Assert.Equal(1, remotes.Count()); + var remote = remotes.First(); + Assert.Equal("default", remote.Id); + Assert.Equal("http://server/path", remote.Url); + Assert.Equal("$/project", remote.Repository); + Assert.Equal("theuser", remote.Username); + Assert.Equal("thepassword", remote.Password); + Assert.Equal("ignorethis.zip", remote.IgnoreRegex); + Assert.Equal(new string[] { "http://old:8080/", "http://other/" }, remote.Aliases); + Assert.True(remote.Autotag); } } - + RemoteConfigConverter _converter = new RemoteConfigConverter(); + + [Fact] + public void MultipleRemotes() + { + var remote1 = new RemoteInfo { Id = "a", Url = "http://a", Repository = "$/a" }; + var remote2 = new RemoteInfo { Id = "b", Url = "http://b", Repository = "$/b" }; + var config = new List(); + config.AddRange(_converter.Dump(remote1)); + config.AddRange(_converter.Dump(remote2)); + var remotes = _converter.Load(config.Where(e => e.Value != null)); + Assert.Equal(2, remotes.Count()); + Assert.Equal(new string[] { "a", "b" }, remotes.Select(r => r.Id).OrderBy(s => s)); + } + [Fact] public void HandlesDotsInName() { var originalRemote = new RemoteInfo { Id = "has.dots.in.it", Url = "http://do/not/care", Repository = "$/do/not/care" }; - var converter = new RemoteConfigConverter(); - var config = converter.Dump(originalRemote); + + var config = _converter.Dump(originalRemote); foreach (var entry in config) Assert.True(entry.Key.StartsWith("tfs-remote.has.dots.in.it."), entry.Key + " should start with tfs-remote.has.dots.in.it"); - var remotes = converter.Load(config.Where(e => e.Value != null)); + + var remotes = _converter.Load(config.Where(e => e.Value != null)); Assert.Equal(1, remotes.Count()); Assert.Equal("has.dots.in.it", remotes.First().Id); } From bbed140adfca5c585b488fac7521073643fa48be Mon Sep 17 00:00:00 2001 From: Jason Finch Date: Wed, 30 Jan 2013 10:31:55 +1000 Subject: [PATCH 08/10] Update README.md Fixing build notes for what worked (from checkout to build) Adding note about submodules. Config Vs2010_Debug doesn't appear to exist, removing Could not build with /p:Configuration=VS11_Debug, setting default action to just the debug build (similar to rake command I guess?) --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9786f8270..dd569db47 100644 --- a/README.md +++ b/README.md @@ -52,8 +52,11 @@ You need .NET 4 and either the 2008 or 2010 version of Team Explorer installed. ### Building -Use `msbuild GitTfs.sln /p:Configuration=Vs2010_Debug` to build for the 2010 version only. +#### Building With MSBuild +1. Update submodules. `git submodule update` to get the libgit2sharp dependencies. +2. Build with `msbuild GitTfs.sln /p:Configuration=debug` for the default debug build. +####Building With Rake You can also do `rake build:debug`. ## Contributing From b3fb187e8159d4dbc4ea17aa84c1170f1235884c Mon Sep 17 00:00:00 2001 From: Matt Burke Date: Wed, 30 Jan 2013 12:01:16 -0500 Subject: [PATCH 09/10] Massage output. --- GitTfs/Commands/ListRemoteBranches.cs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/GitTfs/Commands/ListRemoteBranches.cs b/GitTfs/Commands/ListRemoteBranches.cs index bb31bdf57..940aca8ce 100644 --- a/GitTfs/Commands/ListRemoteBranches.cs +++ b/GitTfs/Commands/ListRemoteBranches.cs @@ -5,10 +5,10 @@ using System.IO; using System.Linq; using NDesk.Options; -using Sep.Git.Tfs.Core; using StructureMap; -using Sep.Git.Tfs.Util; +using Sep.Git.Tfs.Core; using Sep.Git.Tfs.Core.TfsInterop; +using Sep.Git.Tfs.Util; namespace Sep.Git.Tfs.Commands { @@ -48,15 +48,20 @@ public int Run(string tfsUrl) tfsHelper.Username = remoteOptions.Username; tfsHelper.Password = remoteOptions.Password; tfsHelper.EnsureAuthenticated(); - var branches = tfsHelper.GetBranches().ToList(); - stdout.WriteLine("TFS branche(s) that could be cloned:\n"); - foreach (var branchObject in branches.Where(b => b.IsRoot)) + var branches = tfsHelper.GetBranches().Where(b => b.IsRoot).ToList(); + if (branches.IsEmpty()) { - Branch.WriteRemoteTfsBranchStructure(tfsHelper, stdout, branchObject.Path); - stdout.WriteLine(string.Empty); + stdout.WriteLine("No TFS branches were found!"); + } + else + { + stdout.WriteLine("TFS branches that could be cloned:"); + foreach (var branchObject in branches.Where(b => b.IsRoot)) + { + Branch.WriteRemoteTfsBranchStructure(tfsHelper, stdout, branchObject.Path); + } + stdout.WriteLine("\nCloning root branches (marked by [*]) is recommended!"); } - - stdout.WriteLine("\nCloning root branches (marked by [*]) are recommended!"); return GitTfsExitCodes.OK; } } From 3b7b07896ad6f5add7f942429fd3aa3cbb828197 Mon Sep 17 00:00:00 2001 From: Matt Burke Date: Thu, 31 Jan 2013 19:31:47 -0500 Subject: [PATCH 10/10] Update libgit2sharp. I'm not all that pleased by the interface change to Dump, but it works and is simple. This should close #300. --- GitTfs/Core/RemoteConfigConverter.cs | 8 +-- GitTfsTest/Core/RemoteConfigConverterTests.cs | 57 ++++++++++--------- GitTfsTest/GitTfsTest.csproj | 1 + GitTfsTest/Integration/InitTests.cs | 45 +++++++++++++++ GitTfsTest/Integration/IntegrationHelper.cs | 12 ++++ lib/libgit2sharp | 2 +- 6 files changed, 94 insertions(+), 31 deletions(-) create mode 100644 GitTfsTest/Integration/InitTests.cs diff --git a/GitTfs/Core/RemoteConfigConverter.cs b/GitTfs/Core/RemoteConfigConverter.cs index 6986a1b24..0dbb0d334 100644 --- a/GitTfs/Core/RemoteConfigConverter.cs +++ b/GitTfs/Core/RemoteConfigConverter.cs @@ -7,7 +7,7 @@ namespace Sep.Git.Tfs.Core { public class RemoteConfigConverter { - public IEnumerable Load(IEnumerable config) + public IEnumerable Load(IEnumerable> config) { var remotes = new Dictionary(); foreach (var entry in config) @@ -39,7 +39,7 @@ public IEnumerable Load(IEnumerable config) return remotes.Values; } - public IEnumerable Dump(RemoteInfo remote) + public IEnumerable> Dump(RemoteInfo remote) { if (!string.IsNullOrWhiteSpace(remote.Id)) { @@ -54,9 +54,9 @@ public IEnumerable Dump(RemoteInfo remote) } } - private ConfigurationEntry c(string key, string value) + private KeyValuePair c(string key, string value) { - return new ConfigurationEntry(key, value, ConfigurationLevel.Local); + return new KeyValuePair(key, value); } } } diff --git a/GitTfsTest/Core/RemoteConfigConverterTests.cs b/GitTfsTest/Core/RemoteConfigConverterTests.cs index 97603a1ec..d2e5e4177 100644 --- a/GitTfsTest/Core/RemoteConfigConverterTests.cs +++ b/GitTfsTest/Core/RemoteConfigConverterTests.cs @@ -65,24 +65,9 @@ public void DumpsCompleteRemote() AssertContainsConfig("tfs-remote.default.autotag", "true", config); } - private void AssertContainsConfig(string key, string value, IEnumerable configs) + private void AssertContainsConfig(string key, string value, IEnumerable> configs) { - Assert.Contains(new ConfigurationEntry(key, value, ConfigurationLevel.Local), configs, configComparer); - } - - static IEqualityComparer configComparer = new ConfigurationEntryComparer(); - - class ConfigurationEntryComparer : IEqualityComparer - { - bool IEqualityComparer.Equals(ConfigurationEntry x, ConfigurationEntry y) - { - return x.Key == y.Key && x.Value == y.Value; - } - - int IEqualityComparer.GetHashCode(ConfigurationEntry obj) - { - return obj.Key.GetHashCode(); - } + Assert.Contains(new KeyValuePair(key, value), configs); } } @@ -90,16 +75,11 @@ public class LoadTests { RemoteConfigConverter _loader = new RemoteConfigConverter(); - private IEnumerable Load(params ConfigurationEntry[] configs) + private IEnumerable Load(params ConfigurationEntry[] configs) { return _loader.Load(configs); } - private ConfigurationEntry c(string key, string value) - { - return new ConfigurationEntry(key, value, ConfigurationLevel.Local); - } - [Fact] public void NoConfig() { @@ -163,10 +143,10 @@ public void MultipleRemotes() { var remote1 = new RemoteInfo { Id = "a", Url = "http://a", Repository = "$/a" }; var remote2 = new RemoteInfo { Id = "b", Url = "http://b", Repository = "$/b" }; - var config = new List(); + var config = new List>(); config.AddRange(_converter.Dump(remote1)); config.AddRange(_converter.Dump(remote2)); - var remotes = _converter.Load(config.Where(e => e.Value != null)); + var remotes = _converter.Load(magic(config)); Assert.Equal(2, remotes.Count()); Assert.Equal(new string[] { "a", "b" }, remotes.Select(r => r.Id).OrderBy(s => s)); } @@ -180,9 +160,34 @@ public void HandlesDotsInName() foreach (var entry in config) Assert.True(entry.Key.StartsWith("tfs-remote.has.dots.in.it."), entry.Key + " should start with tfs-remote.has.dots.in.it"); - var remotes = _converter.Load(config.Where(e => e.Value != null)); + var remotes = _converter.Load(magic(config)); Assert.Equal(1, remotes.Count()); Assert.Equal("has.dots.in.it", remotes.First().Id); } + + private static IEnumerable> magic(IEnumerable> dumped) + { + return dumped.Where(e => e.Value != null).Select(e => c(e.Key, e.Value)); + } + + private static ConfigurationEntry c(string key, string value) + { + return new TestConfigurationEntry(key, value); + } + + class TestConfigurationEntry : ConfigurationEntry + { + string _key; + string _value; + + public override string Key { get { return _key; } } + public override string Value { get { return _value; } } + + public TestConfigurationEntry(string key, string value) + { + _key = key; + _value = value; + } + } } } diff --git a/GitTfsTest/GitTfsTest.csproj b/GitTfsTest/GitTfsTest.csproj index 65d15d8b1..e2eb01807 100644 --- a/GitTfsTest/GitTfsTest.csproj +++ b/GitTfsTest/GitTfsTest.csproj @@ -129,6 +129,7 @@ + diff --git a/GitTfsTest/Integration/InitTests.cs b/GitTfsTest/Integration/InitTests.cs new file mode 100644 index 000000000..00587be16 --- /dev/null +++ b/GitTfsTest/Integration/InitTests.cs @@ -0,0 +1,45 @@ +using System; +using Sep.Git.Tfs.Core.TfsInterop; + +namespace Sep.Git.Tfs.Test.Integration +{ + public class InitTests : IDisposable + { + IntegrationHelper h; + + public InitTests() + { + h = new IntegrationHelper(); + } + + public void Dispose() + { + h.Dispose(); + } + + [FactExceptOnUnix] + public void InitializesConfig() + { + h.SetupFake(r => { }); + h.Run("init", "http://my-tfs.local/tfs", "$/MyProject", "MyProject"); + h.AssertConfig("MyProject", "tfs-remote.default.url", "http://my-tfs.local/tfs"); + h.AssertConfig("MyProject", "tfs-remote.default.repository", "$/MyProject"); + } + + [FactExceptOnUnix] + public void CanUseThatConfig() + { + h.SetupFake(r => + { + r.Changeset(1, "Project created from template", DateTime.Parse("2012-01-01 12:12:12 -05:00")) + .Change(TfsChangeType.Add, TfsItemType.Folder, "$/MyProject"); + }); + h.Run("init", "http://my-tfs.local/tfs", "$/MyProject", "MyProject"); + h.SetConfig("MyProject", "tfs-remote.default.autotag", "true"); + h.RunIn("MyProject", "fetch"); + var expectedSha = "f8b247c3298f4189c6c9ff701f147af6e1428f97"; + h.AssertRef("MyProject", "refs/remotes/tfs/default", expectedSha); + h.AssertRef("MyProject", "refs/tags/tfs/default/C1", expectedSha); + } + } +} diff --git a/GitTfsTest/Integration/IntegrationHelper.cs b/GitTfsTest/Integration/IntegrationHelper.cs index 7d72d25d2..d7f4fc25f 100644 --- a/GitTfsTest/Integration/IntegrationHelper.cs +++ b/GitTfsTest/Integration/IntegrationHelper.cs @@ -68,6 +68,11 @@ public Repository Repository(string path) #region set up a git repository + public void SetConfig(string repodir, string key, T value) + { + Repository(repodir).Config.Set(key, value); + } + public void SetupGitRepo(string path, Action buildIt) { using (var repo = LibGit2Sharp.Repository.Init(Path.Combine(Workdir, path))) @@ -277,6 +282,13 @@ public void AssertCommitMessage(string repodir, string commitish, string message AssertEqual(message, commit.Message, "Commit message of " + commitish); } + public void AssertConfig(string repodir, string key, T expectedValue) + { + var config = Repository(repodir).Config.Get(key); + Assert.NotNull(config); + Assert.Equal(expectedValue, config.Value); + } + private void AssertEqual(T expected, T actual, string message) { try diff --git a/lib/libgit2sharp b/lib/libgit2sharp index 247ca1a30..68b291eab 160000 --- a/lib/libgit2sharp +++ b/lib/libgit2sharp @@ -1 +1 @@ -Subproject commit 247ca1a30cfb722b74ada4288bcca7293f59b87b +Subproject commit 68b291eab4ec6d6d6def54c879329f0081ef6919