Skip to content

Commit c64f67b

Browse files
committed
rephrase wording and add comments
1 parent a155933 commit c64f67b

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

pkg/commands/branches.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ func (c *GitCommand) GetBranchUpstreamDifferenceCount(branchName string) (string
101101
return c.GetCommitDifferences(branchName, branchName+"@{u}")
102102
}
103103

104-
func (c *GitCommand) GetMainBranch() string {
104+
// TryGetMainBranch tries to get the main branch
105+
// For old repo's this is usually master and for newer once it is main
106+
func (c *GitCommand) TryGetMainBranch() string {
107+
// Firstly try to get the main branch from the origins
105108
cmdStr := `git branch --remotes --list '*/HEAD' --format '%(symref)'`
106109
output, _ := c.OSCommand.RunCommandWithOutput(cmdStr)
107110
lines := strings.Split(strings.TrimSpace(output), "\n")
@@ -112,6 +115,7 @@ func (c *GitCommand) GetMainBranch() string {
112115
}
113116
}
114117

118+
// If we didn't find a main branch from the remotes we check if there is a main or master branch
115119
cmdStr = `git branch --format "%(refname:short)" --list "master" --list "main"`
116120
output, _ = c.OSCommand.RunCommandWithOutput(cmdStr)
117121
lines = append(lines[:0], strings.Split(strings.TrimSpace(output), "\n")...)

pkg/commands/loading_commits.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ func (c *CommitListBuilder) setCommitMergedStatuses(refName string, commits []*m
312312
}
313313

314314
func (c *CommitListBuilder) getMergeBase(refName string) (string, error) {
315-
baseBranch := c.GitCommand.GetMainBranch()
315+
baseBranch := c.GitCommand.TryGetMainBranch()
316316
if baseBranch == "" {
317317
baseBranch = "master"
318318
}

0 commit comments

Comments
 (0)