Skip to content

Commit 165efcc

Browse files
committed
test(check-pr-size): pin initTestRepo's initial branch so go test passes under init.defaultBranch=main
initTestRepo ran `git init -q` with no `-b`, so the fixture repo's first branch was whatever the developer's `init.defaultBranch` happened to be. TestResolveMergeBaseWithAdvancedBaseBranch then runs `git checkout -q -b main <forkPoint>`, which fails with `fatal: a branch named 'main' already exists` on any machine configured with `init.defaultBranch = main`. CI is green only because the ubuntu-latest runner's git still defaults to `master`. Pin the fixture's initial branch to a sentinel name so it can never collide with a branch the tests create themselves. `-b` needs git >= 2.28, the same release that introduced `init.defaultBranch`, so no supported git regresses.
1 parent 75685ed commit 165efcc

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

‎scripts/check-pr-size/main_test.go‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ func gitRun(t *testing.T, dir string, args ...string) string {
3131
func initTestRepo(t *testing.T) string {
3232
t.Helper()
3333
dir := t.TempDir()
34-
gitRun(t, dir, "init", "-q")
34+
// Pin the initial branch so the fixture never collides with a developer's
35+
// init.defaultBranch (tests below create their own "main" branch).
36+
gitRun(t, dir, "init", "-q", "-b", "groom-test-base")
3537
gitRun(t, dir, "config", "user.email", "test@example.com")
3638
gitRun(t, dir, "config", "user.name", "Test")
3739
gitRun(t, dir, "config", "commit.gpgsign", "false")

0 commit comments

Comments
 (0)