Skip to content

Commit 20c935d

Browse files
Using repo.Refs.UpdateTarget instead of adding a new ref for remote repositories
1 parent d56fde9 commit 20c935d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

GitVersion/GitPreparer.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,15 @@ private string GetGitInfoFromUrl()
8484
var branch = repository.FindBranch(BranchName);
8585
if ((branch != null) && !branch.IsCurrentRepositoryHead)
8686
{
87-
var finalName = string.Format("refs/heads/{0}", BranchName);
88-
//repository.Refs.Add("HEAD", branch.UpstreamBranchCanonicalName, true);
87+
// Option 1: checkout (slow)
88+
//repository.Checkout(branch, CheckoutModifiers.Force, null, null);
8989

90-
repository.Refs.Add("HEAD", finalName, true);
90+
// Option 2: add head refs
91+
//var finalName = string.Format("refs/heads/{0}", BranchName);
92+
//repository.Refs.Add("HEAD", finalName, true);
9193

92-
//var symRef = repository.Refs.Create("HEAD", string.Format("refs/heads/{0}", BranchName));
94+
// Option 3: replace head
95+
repository.Refs.UpdateTarget("HEAD", branch.CanonicalName);
9396
}
9497
}
9598
}

0 commit comments

Comments
 (0)