mirror of
https://github.com/jesseduffield/lazygit.git
synced 2026-09-13 17:16:23 -04:00
Merge 2e72dcb3a6 into 8924bca76f
This commit is contained in:
commit
c78e03623c
|
|
@ -77,21 +77,46 @@ func (self *MainBranches) GetMergeBase(refName string) string {
|
|||
}
|
||||
|
||||
func (self *MainBranches) determineMainBranches(configuredMainBranches []string) []string {
|
||||
var existingBranches []string
|
||||
var matchedBranches [][]string
|
||||
var wg sync.WaitGroup
|
||||
|
||||
existingBranches = make([]string, len(configuredMainBranches))
|
||||
matchedBranches = make([][]string, len(configuredMainBranches))
|
||||
|
||||
for i, branchName := range configuredMainBranches {
|
||||
wg.Add(1)
|
||||
go utils.Safe(func() {
|
||||
defer wg.Done()
|
||||
|
||||
// Check for glob patterns first
|
||||
if strings.ContainsAny(branchName, "*?[") {
|
||||
branchPattern := branchName
|
||||
var refs []string
|
||||
|
||||
// Check local branches
|
||||
if output, err := self.cmd.New(
|
||||
NewGitCmd("for-each-ref").Arg("--format=%(refname)", "refs/heads/"+branchPattern).ToArgv(),
|
||||
).DontLog().RunWithOutput(); err == nil {
|
||||
refs = append(refs, strings.Fields(strings.TrimSpace(output))...)
|
||||
}
|
||||
|
||||
// Check remote branches on 'origin'
|
||||
if output, err := self.cmd.New(
|
||||
NewGitCmd("for-each-ref").Arg("--format=%(refname)", "refs/remotes/origin/"+branchPattern).ToArgv(),
|
||||
).DontLog().RunWithOutput(); err == nil {
|
||||
refs = append(refs, strings.Fields(strings.TrimSpace(output))...)
|
||||
}
|
||||
|
||||
matchedBranches[i] = lo.Filter(refs, func(ref string, _ int) bool {
|
||||
return ref != ""
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// Try to determine upstream of local main branch
|
||||
if ref, err := self.cmd.New(
|
||||
NewGitCmd("rev-parse").Arg("--symbolic-full-name", branchName+"@{u}").ToArgv(),
|
||||
).DontLog().RunWithOutput(); err == nil {
|
||||
existingBranches[i] = strings.TrimSpace(ref)
|
||||
matchedBranches[i] = []string{strings.TrimSpace(ref)}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -101,7 +126,7 @@ func (self *MainBranches) determineMainBranches(configuredMainBranches []string)
|
|||
if err := self.cmd.New(
|
||||
NewGitCmd("rev-parse").Arg("--verify", "--quiet", ref).ToArgv(),
|
||||
).DontLog().Run(); err == nil {
|
||||
existingBranches[i] = ref
|
||||
matchedBranches[i] = []string{ref}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -112,16 +137,15 @@ func (self *MainBranches) determineMainBranches(configuredMainBranches []string)
|
|||
if err := self.cmd.New(
|
||||
NewGitCmd("rev-parse").Arg("--verify", "--quiet", ref).ToArgv(),
|
||||
).DontLog().Run(); err == nil {
|
||||
existingBranches[i] = ref
|
||||
matchedBranches[i] = []string{ref}
|
||||
return
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
existingBranches = lo.Filter(existingBranches, func(branch string, _ int) bool {
|
||||
return branch != ""
|
||||
})
|
||||
existingBranches := lo.Flatten(matchedBranches)
|
||||
|
||||
return existingBranches
|
||||
}
|
||||
|
|
|
|||
41
pkg/integration/tests/branch/glob_main_branches.go
Normal file
41
pkg/integration/tests/branch/glob_main_branches.go
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
package branch
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/config"
|
||||
. "github.com/jesseduffield/lazygit/pkg/integration/components"
|
||||
)
|
||||
|
||||
var GlobMainBranches = NewIntegrationTest(NewIntegrationTestArgs{
|
||||
Description: "Verify that glob patterns in mainBranches config match correctly",
|
||||
ExtraCmdArgs: []string{},
|
||||
Skip: false,
|
||||
SetupConfig: func(config *config.AppConfig) {
|
||||
config.GetUserConfig().Git.MainBranches = []string{"release/*"}
|
||||
},
|
||||
SetupRepo: func(shell *Shell) {
|
||||
shell.
|
||||
EmptyCommit("initial").
|
||||
NewBranch("release/1").
|
||||
EmptyCommit("release 1 commit").
|
||||
NewBranchFrom("feature", "release/1").
|
||||
EmptyCommit("feature 1").
|
||||
EmptyCommit("feature 2")
|
||||
},
|
||||
Run: func(t *TestDriver, keys config.KeybindingConfig) {
|
||||
t.Views().Commits().
|
||||
Focus().
|
||||
Lines(
|
||||
Contains("feature 2").IsSelected(),
|
||||
Contains("feature 1"),
|
||||
Contains("release 1 commit"),
|
||||
Contains("initial"),
|
||||
).
|
||||
Press(keys.Commits.SelectCommitsOfCurrentBranch).
|
||||
Lines(
|
||||
Contains("feature 2").IsSelected(),
|
||||
Contains("feature 1").IsSelected(),
|
||||
Contains("release 1 commit"),
|
||||
Contains("initial"),
|
||||
)
|
||||
},
|
||||
})
|
||||
|
|
@ -50,6 +50,7 @@ var tests = []*components.IntegrationTest{
|
|||
branch.DeleteRemoteBranchWithDifferentName,
|
||||
branch.DeleteWhileFiltering,
|
||||
branch.DetachedHead,
|
||||
branch.GlobMainBranches,
|
||||
branch.MergeFastForward,
|
||||
branch.MergeNonFastForward,
|
||||
branch.MoveCommitsToNewBranchFromBaseBranch,
|
||||
|
|
|
|||
Loading…
Reference in a new issue