Skip to content

Commit f90a2fe

Browse files
committed
Stabilize tests against different default branch names
1 parent 68ebcd6 commit f90a2fe

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/NerdBank.GitVersioning.Tests/RepoTestBase.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ protected virtual GitContext InitializeSourceControl(string repoPath, bool withI
103103
{
104104
Repository.Init(repoPath);
105105
var repo = new Repository(repoPath);
106+
107+
// Our tests assume the default branch is master, so retain that regardless of global git configuration on the the machine running the tests.
108+
if (repo.Head.FriendlyName != "master")
109+
{
110+
File.WriteAllText(Path.Combine(repoPath, ".git", "HEAD"), "ref: refs/heads/master\n");
111+
}
112+
106113
repo.Config.Set("user.name", this.Signer.Name, ConfigurationLevel.Local);
107114
repo.Config.Set("user.email", this.Signer.Email, ConfigurationLevel.Local);
108115
foreach (var file in repo.RetrieveStatus().Untracked)

0 commit comments

Comments
 (0)