From 05411e77f743d262097f226c3800af040862f559 Mon Sep 17 00:00:00 2001 From: Chris McDonnell Date: Wed, 3 Dec 2025 01:21:30 -0500 Subject: [PATCH] Add fallback to detecting main branches for fresh repositories All other attempts to determine the main branch fail on a fresh repository right after `git init` because there are no actual commits that these branches point to. --- pkg/commands/git_commands/main_branches.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pkg/commands/git_commands/main_branches.go b/pkg/commands/git_commands/main_branches.go index 109f9cfd847..2cf3927c70a 100644 --- a/pkg/commands/git_commands/main_branches.go +++ b/pkg/commands/git_commands/main_branches.go @@ -113,6 +113,18 @@ func (self *MainBranches) determineMainBranches(configuredMainBranches []string) NewGitCmd("rev-parse").Arg("--verify", "--quiet", ref).ToArgv(), ).DontLog().Run(); err == nil { existingBranches[i] = ref + return + } + + // If this is a brand new repository with no commits, then the current branch would be the default + desiredRef := "refs/heads/" + branchName + if ref, err := self.cmd.New( + NewGitCmd("symbolic-ref").Arg("HEAD").ToArgv(), + ).DontLog().RunWithOutput(); err == nil { + if strings.TrimSpace(ref) == desiredRef { + existingBranches[i] = desiredRef + return + } } }) }