diff --git a/GitTfsTest/Integration/BootstrapTests.cs b/GitTfsTest/Integration/BootstrapTests.cs index fba58b1b..61a1f2af 100644 --- a/GitTfsTest/Integration/BootstrapTests.cs +++ b/GitTfsTest/Integration/BootstrapTests.cs @@ -1,6 +1,7 @@ using System; using Sep.Git.Tfs.Core.TfsInterop; using Xunit; +using LibGit2Sharp; namespace Sep.Git.Tfs.Test.Integration { @@ -73,5 +74,38 @@ namespace Sep.Git.Tfs.Test.Integration h.RunIn("repo", "fetch", "-I"); h.AssertRef("repo", "tfs/default", c1); } + + [Fact] + public void WhenUsingIOption_ThenAutoBootstrapingOneBrancheInAdditionToMaster() + { + int ChangesetIdToTrickFetch = 1; + h.SetupFake(r => + { + r.Changeset(ChangesetIdToTrickFetch, "UseLess! Just to have the same changeset Id that the commit already in repo (and fetch nothing)", DateTime.Parse("2012-01-01 12:12:12 -05:00")) + .Change(TfsChangeType.Add, TfsItemType.Folder, "$/MyProject"); + }); + + string c1 = null; + string c2 = null; + h.SetupGitRepo("repo", g => + { + c1 = g.Commit("A sample commit from TFS.\n\ngit-tfs-id: [http://server/tfs]$/MyProject/trunk;C" + ChangesetIdToTrickFetch); + g.CreateBranch("branch"); + c2 = g.Commit("A sample commit from TFS.\n\ngit-tfs-id: [http://server/tfs]$/MyProject/branch;C" + ChangesetIdToTrickFetch); + }); + + using (var repo = h.GetRepository("repo")) + { + repo.Checkout("master"); + h.AssertNoRef("repo", "tfs/default"); + h.RunIn("repo", "fetch", "-I"); + h.AssertRef("repo", "tfs/default", c1); + + repo.Checkout("branch"); + h.AssertNoRef("repo", "tfs/branch"); + h.RunIn("repo", "fetch", "-I"); + h.AssertRef("repo", "tfs/branch", c2); + } + } } } diff --git a/GitTfsTest/Integration/IntegrationHelper.cs b/GitTfsTest/Integration/IntegrationHelper.cs index bd13d5bf..b99bb544 100644 --- a/GitTfsTest/Integration/IntegrationHelper.cs +++ b/GitTfsTest/Integration/IntegrationHelper.cs @@ -72,11 +72,18 @@ namespace Sep.Git.Tfs.Test.Integration public void SetupGitRepo(string path, Action buildIt) { - var repoPath = LibGit2Sharp.Repository.Init(Path.Combine(Workdir, path)); + var fullPath = Path.Combine(Workdir, path); + System.Diagnostics.Trace.WriteLine("Repository path:" + fullPath); + var repoPath = LibGit2Sharp.Repository.Init(fullPath); using (var repo = new Repository(repoPath)) buildIt(new RepoBuilder(repo)); } + public Repository GetRepository(string path) + { + return new Repository(Path.Combine(Workdir, path)); + } + public class RepoBuilder { private Repository _repo; @@ -93,6 +100,16 @@ namespace Sep.Git.Tfs.Test.Integration var committer = new Signature("Test User", "test@example.com", new DateTimeOffset(DateTime.Now)); return _repo.Commit(message, committer, committer).Id.Sha; } + + public void CreateBranch(string branchName) + { + _repo.Checkout(_repo.CreateBranch(branchName)); + } + + public void Checkout(string commitishName) + { + _repo.Checkout(commitishName); + } } #endregion