From cf20ce0ea6fc0565b9283b65abaecd80ffe60100 Mon Sep 17 00:00:00 2001 From: Philippe Miossec Date: Sat, 19 Apr 2014 23:38:06 +0200 Subject: [PATCH] Unit test for Autobootsrap when using -I option on a branch Auto bootstap 'tfs/default' for first remote created Auto bootstap 'tfs/branch' for second remote created Extand IntegrationHelper to be able to create a more complexe test case... --- GitTfsTest/Integration/BootstrapTests.cs | 34 +++++++++++++++++++++ GitTfsTest/Integration/IntegrationHelper.cs | 19 +++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) 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