mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-04 23:37:41 +02:00
Merge pull request #2692 from stefanhaller/fetch-all
Add --all to "git fetch" command, unless disabled by config.
This commit is contained in:
commit
523be47865
@ -94,6 +94,7 @@ git:
|
|||||||
mainBranches: [master, main]
|
mainBranches: [master, main]
|
||||||
autoFetch: true
|
autoFetch: true
|
||||||
autoRefresh: true
|
autoRefresh: true
|
||||||
|
fetchAll: true # Pass --all flag when running git fetch. Set to false to fetch only origin (or the current branch's upstream remote if there is one)
|
||||||
branchLogCmd: 'git log --graph --color=always --abbrev-commit --decorate --date=relative --pretty=medium {{branchName}} --'
|
branchLogCmd: 'git log --graph --color=always --abbrev-commit --decorate --date=relative --pretty=medium {{branchName}} --'
|
||||||
allBranchesLogCmd: 'git log --graph --all --color=always --abbrev-commit --decorate --date=relative --pretty=medium'
|
allBranchesLogCmd: 'git log --graph --all --color=always --abbrev-commit --decorate --date=relative --pretty=medium'
|
||||||
overrideGpg: false # prevents lazygit from spawning a separate process when using GPG
|
overrideGpg: false # prevents lazygit from spawning a separate process when using GPG
|
||||||
|
@ -50,15 +50,12 @@ func (self *SyncCommands) Push(opts PushOpts) error {
|
|||||||
|
|
||||||
type FetchOptions struct {
|
type FetchOptions struct {
|
||||||
Background bool
|
Background bool
|
||||||
RemoteName string
|
|
||||||
BranchName string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fetch fetch git repo
|
// Fetch fetch git repo
|
||||||
func (self *SyncCommands) Fetch(opts FetchOptions) error {
|
func (self *SyncCommands) FetchCmdObj(opts FetchOptions) oscommands.ICmdObj {
|
||||||
cmdArgs := NewGitCmd("fetch").
|
cmdArgs := NewGitCmd("fetch").
|
||||||
ArgIf(opts.RemoteName != "", opts.RemoteName).
|
ArgIf(self.UserConfig.Git.FetchAll, "--all").
|
||||||
ArgIf(opts.BranchName != "", opts.BranchName).
|
|
||||||
ToArgv()
|
ToArgv()
|
||||||
|
|
||||||
cmdObj := self.cmd.New(cmdArgs)
|
cmdObj := self.cmd.New(cmdArgs)
|
||||||
@ -67,7 +64,12 @@ func (self *SyncCommands) Fetch(opts FetchOptions) error {
|
|||||||
} else {
|
} else {
|
||||||
cmdObj.PromptOnCredentialRequest()
|
cmdObj.PromptOnCredentialRequest()
|
||||||
}
|
}
|
||||||
return cmdObj.WithMutex(self.syncMutex).Run()
|
return cmdObj.WithMutex(self.syncMutex)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (self *SyncCommands) Fetch(opts FetchOptions) error {
|
||||||
|
cmdObj := self.FetchCmdObj(opts)
|
||||||
|
return cmdObj.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
type PullOptions struct {
|
type PullOptions struct {
|
||||||
|
@ -92,3 +92,64 @@ func TestSyncPush(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSyncFetch(t *testing.T) {
|
||||||
|
type scenario struct {
|
||||||
|
testName string
|
||||||
|
opts FetchOptions
|
||||||
|
fetchAllConfig bool
|
||||||
|
test func(oscommands.ICmdObj)
|
||||||
|
}
|
||||||
|
|
||||||
|
scenarios := []scenario{
|
||||||
|
{
|
||||||
|
testName: "Fetch in foreground (all=false)",
|
||||||
|
opts: FetchOptions{Background: false},
|
||||||
|
fetchAllConfig: false,
|
||||||
|
test: func(cmdObj oscommands.ICmdObj) {
|
||||||
|
assert.True(t, cmdObj.ShouldLog())
|
||||||
|
assert.Equal(t, cmdObj.GetCredentialStrategy(), oscommands.PROMPT)
|
||||||
|
assert.Equal(t, cmdObj.Args(), []string{"git", "fetch"})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: "Fetch in foreground (all=true)",
|
||||||
|
opts: FetchOptions{Background: false},
|
||||||
|
fetchAllConfig: true,
|
||||||
|
test: func(cmdObj oscommands.ICmdObj) {
|
||||||
|
assert.True(t, cmdObj.ShouldLog())
|
||||||
|
assert.Equal(t, cmdObj.GetCredentialStrategy(), oscommands.PROMPT)
|
||||||
|
assert.Equal(t, cmdObj.Args(), []string{"git", "fetch", "--all"})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: "Fetch in background (all=false)",
|
||||||
|
opts: FetchOptions{Background: true},
|
||||||
|
fetchAllConfig: false,
|
||||||
|
test: func(cmdObj oscommands.ICmdObj) {
|
||||||
|
assert.False(t, cmdObj.ShouldLog())
|
||||||
|
assert.Equal(t, cmdObj.GetCredentialStrategy(), oscommands.FAIL)
|
||||||
|
assert.Equal(t, cmdObj.Args(), []string{"git", "fetch"})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
testName: "Fetch in background (all=true)",
|
||||||
|
opts: FetchOptions{Background: true},
|
||||||
|
fetchAllConfig: true,
|
||||||
|
test: func(cmdObj oscommands.ICmdObj) {
|
||||||
|
assert.False(t, cmdObj.ShouldLog())
|
||||||
|
assert.Equal(t, cmdObj.GetCredentialStrategy(), oscommands.FAIL)
|
||||||
|
assert.Equal(t, cmdObj.Args(), []string{"git", "fetch", "--all"})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, s := range scenarios {
|
||||||
|
s := s
|
||||||
|
t.Run(s.testName, func(t *testing.T) {
|
||||||
|
instance := buildSyncCommands(commonDeps{})
|
||||||
|
instance.UserConfig.Git.FetchAll = s.fetchAllConfig
|
||||||
|
s.test(instance.FetchCmdObj(s.opts))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -81,6 +81,7 @@ type GitConfig struct {
|
|||||||
SkipHookPrefix string `yaml:"skipHookPrefix"`
|
SkipHookPrefix string `yaml:"skipHookPrefix"`
|
||||||
AutoFetch bool `yaml:"autoFetch"`
|
AutoFetch bool `yaml:"autoFetch"`
|
||||||
AutoRefresh bool `yaml:"autoRefresh"`
|
AutoRefresh bool `yaml:"autoRefresh"`
|
||||||
|
FetchAll bool `yaml:"fetchAll"`
|
||||||
BranchLogCmd string `yaml:"branchLogCmd"`
|
BranchLogCmd string `yaml:"branchLogCmd"`
|
||||||
AllBranchesLogCmd string `yaml:"allBranchesLogCmd"`
|
AllBranchesLogCmd string `yaml:"allBranchesLogCmd"`
|
||||||
OverrideGpg bool `yaml:"overrideGpg"`
|
OverrideGpg bool `yaml:"overrideGpg"`
|
||||||
@ -453,6 +454,7 @@ func GetDefaultConfig() *UserConfig {
|
|||||||
MainBranches: []string{"master", "main"},
|
MainBranches: []string{"master", "main"},
|
||||||
AutoFetch: true,
|
AutoFetch: true,
|
||||||
AutoRefresh: true,
|
AutoRefresh: true,
|
||||||
|
FetchAll: true,
|
||||||
BranchLogCmd: "git log --graph --color=always --abbrev-commit --decorate --date=relative --pretty=medium {{branchName}} --",
|
BranchLogCmd: "git log --graph --color=always --abbrev-commit --decorate --date=relative --pretty=medium {{branchName}} --",
|
||||||
AllBranchesLogCmd: "git log --graph --all --color=always --abbrev-commit --decorate --date=relative --pretty=medium",
|
AllBranchesLogCmd: "git log --graph --all --color=always --abbrev-commit --decorate --date=relative --pretty=medium",
|
||||||
DisableForcePushing: false,
|
DisableForcePushing: false,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user