From f90a2fee3692f70dec234283c72cff976267e59d Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Sun, 1 May 2022 13:33:08 -0600 Subject: [PATCH] Stabilize tests against different default branch names --- src/NerdBank.GitVersioning.Tests/RepoTestBase.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/NerdBank.GitVersioning.Tests/RepoTestBase.cs b/src/NerdBank.GitVersioning.Tests/RepoTestBase.cs index 5cc81647..473f0bd9 100644 --- a/src/NerdBank.GitVersioning.Tests/RepoTestBase.cs +++ b/src/NerdBank.GitVersioning.Tests/RepoTestBase.cs @@ -103,6 +103,13 @@ protected virtual GitContext InitializeSourceControl(string repoPath, bool withI { Repository.Init(repoPath); var repo = new Repository(repoPath); + + // Our tests assume the default branch is master, so retain that regardless of global git configuration on the the machine running the tests. + if (repo.Head.FriendlyName != "master") + { + File.WriteAllText(Path.Combine(repoPath, ".git", "HEAD"), "ref: refs/heads/master\n"); + } + repo.Config.Set("user.name", this.Signer.Name, ConfigurationLevel.Local); repo.Config.Set("user.email", this.Signer.Email, ConfigurationLevel.Local); foreach (var file in repo.RetrieveStatus().Untracked)