Skip to content

Commit 9fcc482

Browse files
Allow move of repository head for dynamic repositories
1 parent 32b4083 commit 9fcc482

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

src/GitVersionCore/GitPreparer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void Initialise(bool normaliseGitDirectory, string currentBranch, bool sh
5050
{
5151
CleanupDuplicateOrigin();
5252
}
53-
GitRepositoryHelper.NormalizeGitDirectory(GetDotGitDirectory(), authentication, noFetch, currentBranch);
53+
GitRepositoryHelper.NormalizeGitDirectory(GetDotGitDirectory(), authentication, noFetch, currentBranch, IsDynamicGitRepository);
5454
}
5555
}
5656
return;
@@ -180,7 +180,7 @@ static string CreateDynamicRepository(string targetPath, AuthenticationInfo auth
180180
Logger.WriteInfo("Git repository already exists");
181181
using (Logger.IndentLog($"Normalizing git directory for branch '{targetBranch}'"))
182182
{
183-
GitRepositoryHelper.NormalizeGitDirectory(gitDirectory, authentication, noFetch, targetBranch);
183+
GitRepositoryHelper.NormalizeGitDirectory(gitDirectory, authentication, noFetch, targetBranch, true);
184184
}
185185

186186
return gitDirectory;
@@ -191,7 +191,7 @@ static string CreateDynamicRepository(string targetPath, AuthenticationInfo auth
191191
using (Logger.IndentLog($"Normalizing git directory for branch '{targetBranch}'"))
192192
{
193193
// Normalize (download branches) before using the branch
194-
GitRepositoryHelper.NormalizeGitDirectory(gitDirectory, authentication, noFetch, targetBranch);
194+
GitRepositoryHelper.NormalizeGitDirectory(gitDirectory, authentication, noFetch, targetBranch, true);
195195
}
196196

197197
return gitDirectory;

src/GitVersionCore/Helpers/GitRepositoryHelper.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ public static class GitRepositoryHelper
1111
/// Normalisation of a git directory turns all remote branches into local branches, turns pull request refs into a real branch and a few other things. This is designed to be run *only on the build server* which checks out repositories in different ways.
1212
/// It is not recommended to run normalisation against a local repository
1313
/// </summary>
14-
public static void NormalizeGitDirectory(string gitDirectory, AuthenticationInfo authentication, bool noFetch, string currentBranch)
14+
public static void NormalizeGitDirectory(string gitDirectory, AuthenticationInfo authentication,
15+
bool noFetch, string currentBranch, bool isDynamicRepository)
1516
{
1617
using (var repo = new Repository(gitDirectory))
1718
{
@@ -41,7 +42,7 @@ public static void NormalizeGitDirectory(string gitDirectory, AuthenticationInfo
4142
// Bug fix for https://github.com/GitTools/GitVersion/issues/1754, head maybe have been changed
4243
// if this is a dynamic repository. But only allow this in case the branches are different (branch switch)
4344
if (expectedSha != repo.Head.Tip.Sha &&
44-
!expectedBranchName.IsBranch(currentBranch))
45+
(isDynamicRepository || !expectedBranchName.IsBranch(currentBranch)))
4546
{
4647
var newExpectedSha = repo.Head.Tip.Sha;
4748
var newExpectedBranchName = repo.Head.CanonicalName;

0 commit comments

Comments
 (0)