Skip to content

Commit 557ae18

Browse files
committed
amend! Add config git.baseBranches
Add config git.mainBranches It defaults to {"master", "main"}, but can be set to whatever branch names are used as base branches, e.g. {"master", "devel", "v1.0-hotfixes"}. It is used for color-coding the shas in the commit list, i.e. to decide whether commits are green or yellow.
1 parent 2a7765f commit 557ae18

File tree

4 files changed

+30
-32
lines changed

4 files changed

+30
-32
lines changed

docs/Config.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,9 @@ git:
8888
# displays the whole git graph by default in the commits panel (equivalent to passing the `--all` argument to `git log`)
8989
showWholeGraph: false
9090
skipHookPrefix: WIP
91-
# The main branches. We colour commits green if
92-
# they belong to one of these branches, so that you can easily see which commits are
93-
# unique to your branch (coloured in yellow)
94-
baseBranches: [master, main]
91+
# The main branches. We colour commits green if they belong to one of these branches,
92+
# so that you can easily see which commits are unique to your branch (coloured in yellow)
93+
mainBranches: [master, main]
9594
autoFetch: true
9695
autoRefresh: true
9796
branchLogCmd: 'git log --graph --color=always --abbrev-commit --decorate --date=relative --pretty=medium {{branchName}} --'

pkg/commands/git_commands/commit_loader.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ type CommitLoader struct {
3333
readFile func(filename string) ([]byte, error)
3434
walkFiles func(root string, fn filepath.WalkFunc) error
3535
dotGitDir string
36-
// List of base branches that exist in the repo, quoted for direct use in a git command.
36+
// List of main branches that exist in the repo, quoted for direct use in a git command.
3737
// We use these to obtain the merge base of the branch.
38-
// When nil, we're yet to obtain the list of base branches.
39-
quotedBaseBranches *string
38+
// When nil, we're yet to obtain the list of main branches.
39+
quotedMainBranches *string
4040
}
4141

4242
// making our dependencies explicit for the sake of easier testing
@@ -53,7 +53,7 @@ func NewCommitLoader(
5353
readFile: os.ReadFile,
5454
walkFiles: filepath.Walk,
5555
dotGitDir: dotGitDir,
56-
quotedBaseBranches: nil,
56+
quotedMainBranches: nil,
5757
}
5858
}
5959

@@ -365,38 +365,37 @@ func (self *CommitLoader) setCommitMergedStatuses(refName string, commits []*mod
365365
}
366366

367367
func (self *CommitLoader) getMergeBase(refName string) string {
368-
if self.quotedBaseBranches == nil {
369-
self.quotedBaseBranches = lo.ToPtr(self.getExistingBaseBranches())
368+
if self.quotedMainBranches == nil {
369+
self.quotedMainBranches = lo.ToPtr(self.getExistingMainBranches())
370370
}
371371

372-
if *self.quotedBaseBranches == "" {
372+
if *self.quotedMainBranches == "" {
373373
return ""
374374
}
375375

376-
// We pass all configured base branches to the merge-base call; git will
376+
// We pass all configured main branches to the merge-base call; git will
377377
// return the base commit for the closest one.
378378
output, err := self.cmd.New(fmt.Sprintf("git merge-base %s %s",
379-
self.cmd.Quote(refName), *self.quotedBaseBranches)).DontLog().RunWithOutput()
379+
self.cmd.Quote(refName), *self.quotedMainBranches)).DontLog().RunWithOutput()
380380
if err != nil {
381-
// If there's an error, it must be because one of the base branches that
382-
// used to exist when we called getExistingBaseBranches() was deleted
381+
// If there's an error, it must be because one of the main branches that
382+
// used to exist when we called getExistingMainBranches() was deleted
383383
// meanwhile. To fix this for next time, throw away our cache.
384-
self.quotedBaseBranches = nil
384+
self.quotedMainBranches = nil
385385
}
386386
return ignoringWarnings(output)
387387
}
388388

389-
func (self *CommitLoader) getExistingBaseBranches() string {
390-
quotedBaseBranches := strings.Join(
391-
lo.FilterMap(self.UserConfig.Git.BaseBranches,
389+
func (self *CommitLoader) getExistingMainBranches() string {
390+
return strings.Join(
391+
lo.FilterMap(self.UserConfig.Git.MainBranches,
392392
func(branchName string, _ int) (string, bool) {
393393
quotedRef := self.cmd.Quote("refs/heads/" + branchName)
394394
if err := self.cmd.New(fmt.Sprintf("git rev-parse --verify --quiet %s", quotedRef)).DontLog().Run(); err != nil {
395395
return "", false
396396
}
397397
return quotedRef, true
398398
}), " ")
399-
return quotedBaseBranches
400399
}
401400

402401
func ignoringWarnings(commandOutput string) string {

pkg/commands/git_commands/commit_loader_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestGetCommits(t *testing.T) {
3333
logOrder string
3434
rebaseMode enums.RebaseMode
3535
opts GetCommitsOptions
36-
baseBranches []string
36+
mainBranches []string
3737
}
3838

3939
scenarios := []scenario{
@@ -66,13 +66,13 @@ func TestGetCommits(t *testing.T) {
6666
logOrder: "topo-order",
6767
rebaseMode: enums.REBASE_MODE_NONE,
6868
opts: GetCommitsOptions{RefName: "HEAD", IncludeRebaseCommits: false},
69-
baseBranches: []string{"master", "main"},
69+
mainBranches: []string{"master", "main"},
7070
runner: oscommands.NewFakeRunner(t).
7171
// here it's seeing which commits are yet to be pushed
7272
Expect(`git merge-base "HEAD" "HEAD"@{u}`, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164", nil).
7373
// here it's actually getting all the commits in a formatted form, one per line
7474
Expect(`git log "HEAD" --topo-order --oneline --pretty=format:"%H%x00%at%x00%aN%x00%ae%x00%d%x00%p%x00%s" --abbrev=40 --no-show-signature --`, commitsOutput, nil).
75-
// here it's testing which of the configured base branches exist
75+
// here it's testing which of the configured main branches exist
7676
Expect(`git rev-parse --verify --quiet "refs/heads/master"`, "", nil). // this one does
7777
Expect(`git rev-parse --verify --quiet "refs/heads/main"`, "", errors.New("error")). // this one doesn't
7878
// here it's seeing where our branch diverged from the master branch so that we can mark that commit and parent commits as 'merged'
@@ -195,17 +195,17 @@ func TestGetCommits(t *testing.T) {
195195
expectedError: nil,
196196
},
197197
{
198-
testName: "should not call merge-base for baseBranches if none exist",
198+
testName: "should not call merge-base for mainBranches if none exist",
199199
logOrder: "topo-order",
200200
rebaseMode: enums.REBASE_MODE_NONE,
201201
opts: GetCommitsOptions{RefName: "HEAD", IncludeRebaseCommits: false},
202-
baseBranches: []string{"master", "main"},
202+
mainBranches: []string{"master", "main"},
203203
runner: oscommands.NewFakeRunner(t).
204204
// here it's seeing which commits are yet to be pushed
205205
Expect(`git merge-base "HEAD" "HEAD"@{u}`, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164", nil).
206206
// here it's actually getting all the commits in a formatted form, one per line
207207
Expect(`git log "HEAD" --topo-order --oneline --pretty=format:"%H%x00%at%x00%aN%x00%ae%x00%d%x00%p%x00%s" --abbrev=40 --no-show-signature --`, singleCommitOutput, nil).
208-
// here it's testing which of the configured base branches exist; neither does
208+
// here it's testing which of the configured main branches exist; neither does
209209
Expect(`git rev-parse --verify --quiet "refs/heads/master"`, "", errors.New("error")).
210210
Expect(`git rev-parse --verify --quiet "refs/heads/main"`, "", errors.New("error")),
211211

@@ -228,17 +228,17 @@ func TestGetCommits(t *testing.T) {
228228
expectedError: nil,
229229
},
230230
{
231-
testName: "should call merge-base for all base branches that exist",
231+
testName: "should call merge-base for all main branches that exist",
232232
logOrder: "topo-order",
233233
rebaseMode: enums.REBASE_MODE_NONE,
234234
opts: GetCommitsOptions{RefName: "HEAD", IncludeRebaseCommits: false},
235-
baseBranches: []string{"master", "main", "develop", "1.0-hotfixes"},
235+
mainBranches: []string{"master", "main", "develop", "1.0-hotfixes"},
236236
runner: oscommands.NewFakeRunner(t).
237237
// here it's seeing which commits are yet to be pushed
238238
Expect(`git merge-base "HEAD" "HEAD"@{u}`, "b21997d6b4cbdf84b149d8e6a2c4d06a8e9ec164", nil).
239239
// here it's actually getting all the commits in a formatted form, one per line
240240
Expect(`git log "HEAD" --topo-order --oneline --pretty=format:"%H%x00%at%x00%aN%x00%ae%x00%d%x00%p%x00%s" --abbrev=40 --no-show-signature --`, singleCommitOutput, nil).
241-
// here it's testing which of the configured base branches exist
241+
// here it's testing which of the configured main branches exist
242242
Expect(`git rev-parse --verify --quiet "refs/heads/master"`, "", nil).
243243
Expect(`git rev-parse --verify --quiet "refs/heads/main"`, "", errors.New("error")).
244244
Expect(`git rev-parse --verify --quiet "refs/heads/develop"`, "", nil).
@@ -309,7 +309,7 @@ func TestGetCommits(t *testing.T) {
309309
},
310310
}
311311

312-
common.UserConfig.Git.BaseBranches = scenario.baseBranches
312+
common.UserConfig.Git.MainBranches = scenario.mainBranches
313313
commits, err := builder.GetCommits(scenario.opts)
314314

315315
assert.Equal(t, scenario.expectedCommits, commits)

pkg/config/user_config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ type GitConfig struct {
7676
Paging PagingConfig `yaml:"paging"`
7777
Commit CommitConfig `yaml:"commit"`
7878
Merging MergingConfig `yaml:"merging"`
79-
BaseBranches []string `yaml:"baseBranches"`
79+
MainBranches []string `yaml:"mainBranches"`
8080
SkipHookPrefix string `yaml:"skipHookPrefix"`
8181
AutoFetch bool `yaml:"autoFetch"`
8282
AutoRefresh bool `yaml:"autoRefresh"`
@@ -444,7 +444,7 @@ func GetDefaultConfig() *UserConfig {
444444
ShowWholeGraph: false,
445445
},
446446
SkipHookPrefix: "WIP",
447-
BaseBranches: []string{"master", "main"},
447+
MainBranches: []string{"master", "main"},
448448
AutoFetch: true,
449449
AutoRefresh: true,
450450
BranchLogCmd: "git log --graph --color=always --abbrev-commit --decorate --date=relative --pretty=medium {{branchName}} --",

0 commit comments

Comments
 (0)