diff --git a/GitVersionCore.Tests/GitVersionCore.Tests.csproj b/GitVersionCore.Tests/GitVersionCore.Tests.csproj index 31f297827b..3b40ffde11 100644 --- a/GitVersionCore.Tests/GitVersionCore.Tests.csproj +++ b/GitVersionCore.Tests/GitVersionCore.Tests.csproj @@ -57,9 +57,9 @@ False ..\packages\NUnit.2.6.4\lib\nunit.framework.dll - - False - ..\packages\Shouldly.2.4.0\lib\net40\Shouldly.dll + + ..\packages\Shouldly.2.5.0\lib\net40\Shouldly.dll + True diff --git a/GitVersionCore.Tests/packages.config b/GitVersionCore.Tests/packages.config index 7f7e52452c..e0a13f8d56 100644 --- a/GitVersionCore.Tests/packages.config +++ b/GitVersionCore.Tests/packages.config @@ -6,6 +6,6 @@ - + \ No newline at end of file diff --git a/GitVersionCore/BuildServers/GitHelper.cs b/GitVersionCore/BuildServers/GitHelper.cs index 927189e7ba..5071804a63 100644 --- a/GitVersionCore/BuildServers/GitHelper.cs +++ b/GitVersionCore/BuildServers/GitHelper.cs @@ -12,7 +12,11 @@ public static class GitHelper public static void NormalizeGitDirectory(string gitDirectory, Authentication authentication, bool noFetch) { //If noFetch is enabled, then GitVersion will assume that the git repository is normalized before execution, so that fetching from remotes is not required. - if (noFetch) return; + if (noFetch) + { + Logger.WriteInfo("Skipping fetching"); + return; + } using (var repo = new Repository(gitDirectory)) { diff --git a/GitVersionExe.Tests/GitPreparerTests.cs b/GitVersionExe.Tests/GitPreparerTests.cs index 5fa000fd96..bc77b5217b 100644 --- a/GitVersionExe.Tests/GitPreparerTests.cs +++ b/GitVersionExe.Tests/GitPreparerTests.cs @@ -78,6 +78,51 @@ public void WorksCorrectlyWithRemoteRepository(string branchName, string expecte } } + [Test] + public void UpdatesExistingDynamicRepository() + { + var repoName = Guid.NewGuid().ToString(); + var tempPath = Path.GetTempPath(); + var tempDir = Path.Combine(tempPath, repoName); + Directory.CreateDirectory(tempDir); + string dynamicRepositoryPath = null; + + try + { + using (var mainRepositoryFixture = new EmptyRepositoryFixture(new Config())) + { + mainRepositoryFixture.Repository.MakeCommits(1); + + var arguments = new Arguments + { + TargetPath = tempDir, + TargetUrl = mainRepositoryFixture.RepositoryPath, + TargetBranch = "master" + }; + + var gitPreparer = new GitPreparer(arguments); + gitPreparer.InitialiseDynamicRepositoryIfNeeded(); + dynamicRepositoryPath = gitPreparer.GetDotGitDirectory(); + + var newCommit = mainRepositoryFixture.Repository.MakeACommit(); + gitPreparer.InitialiseDynamicRepositoryIfNeeded(); + + using (var repository = new Repository(dynamicRepositoryPath)) + { + mainRepositoryFixture.DumpGraph(); + repository.DumpGraph(); + repository.Commits.ShouldContain(c => c.Sha == newCommit.Sha); + } + } + } + finally + { + Directory.Delete(tempDir, true); + if (dynamicRepositoryPath != null) + DeleteHelper.DeleteGitRepository(dynamicRepositoryPath); + } + } + [Test] public void PicksAnotherDirectoryNameWhenDynamicRepoFolderTaken() { diff --git a/GitVersionExe.Tests/GitVersionExe.Tests.csproj b/GitVersionExe.Tests/GitVersionExe.Tests.csproj index ae720b8090..9319561d79 100644 --- a/GitVersionExe.Tests/GitVersionExe.Tests.csproj +++ b/GitVersionExe.Tests/GitVersionExe.Tests.csproj @@ -53,9 +53,9 @@ False ..\packages\NUnit.2.6.4\lib\nunit.framework.dll - - False - ..\packages\Shouldly.2.4.0\lib\net40\Shouldly.dll + + ..\packages\Shouldly.2.5.0\lib\net40\Shouldly.dll + True diff --git a/GitVersionExe.Tests/packages.config b/GitVersionExe.Tests/packages.config index eaa8085803..7e97b56f24 100644 --- a/GitVersionExe.Tests/packages.config +++ b/GitVersionExe.Tests/packages.config @@ -5,5 +5,5 @@ - + \ No newline at end of file diff --git a/GitVersionExe/GitPreparer.cs b/GitVersionExe/GitPreparer.cs index e52011c10a..6196dde50c 100644 --- a/GitVersionExe/GitPreparer.cs +++ b/GitVersionExe/GitPreparer.cs @@ -83,7 +83,19 @@ static string CreateDynamicRepository(string targetPath, Authentication authenti var gitDirectory = Path.Combine(targetPath, ".git"); if (Directory.Exists(targetPath)) { - Logger.WriteInfo("Git repository already exists at {0}, skipping clone"); + Logger.WriteInfo(string.Format("Git repository already exists at {0}", targetPath)); + GitHelper.NormalizeGitDirectory(gitDirectory, authentication, noFetch); + Logger.WriteInfo(string.Format("Updating branch '{0}'", targetBranch)); + using (var repo = new Repository(targetPath)) + { + var targetGitBranch = repo.Branches[targetBranch]; + var trackedBranch = targetGitBranch.TrackedBranch; + if (trackedBranch == null) + throw new InvalidOperationException(string.Format("Expecting {0} to have a remote tracking branch", targetBranch)); + + targetGitBranch.Checkout(); + repo.Reset(ResetMode.Hard, trackedBranch.Tip); + } return gitDirectory; } @@ -105,7 +117,6 @@ static string CreateDynamicRepository(string targetPath, Authentication authenti Repository.Clone(repositoryUrl, gitDirectory, new CloneOptions { - IsBare = true, Checkout = false, CredentialsProvider = (url, usernameFromUrl, types) => credentials }); diff --git a/GitVersionTask.Tests/GitVersionTask.Tests.csproj b/GitVersionTask.Tests/GitVersionTask.Tests.csproj index 4d5bc3e9d6..92dca843e8 100644 --- a/GitVersionTask.Tests/GitVersionTask.Tests.csproj +++ b/GitVersionTask.Tests/GitVersionTask.Tests.csproj @@ -80,9 +80,9 @@ False ..\packages\ObjectApproval.1.0.0\Lib\NET40\ObjectApproval.dll - - False - ..\packages\Shouldly.2.4.0\lib\net40\Shouldly.dll + + ..\packages\Shouldly.2.5.0\lib\net40\Shouldly.dll + True diff --git a/GitVersionTask.Tests/packages.config b/GitVersionTask.Tests/packages.config index bcfff2cd85..0bf2c676ba 100644 --- a/GitVersionTask.Tests/packages.config +++ b/GitVersionTask.Tests/packages.config @@ -11,7 +11,7 @@ - + \ No newline at end of file