summaryrefslogtreecommitdiffstats
path: root/pkg/commands
diff options
context:
space:
mode:
authorStefan Haller <stefan@haller-berlin.de>2023-03-01 09:09:35 +0100
committerStefan Haller <stefan@haller-berlin.de>2023-06-01 10:13:14 +0200
commit31a2ea1f19184a10239d8c02314d46321a0e0ae3 (patch)
tree08371c01bea1cb2a795683ddd18feb196dc8d6af /pkg/commands
parent697157f5d57ef674eca2d2ee5236d6f2736b2f61 (diff)
Add --all to "git fetch" command when not fetching a specific remote
Diffstat (limited to 'pkg/commands')
-rw-r--r--pkg/commands/git_commands/sync.go4
-rw-r--r--pkg/commands/git_commands/sync_test.go38
2 files changed, 34 insertions, 8 deletions
diff --git a/pkg/commands/git_commands/sync.go b/pkg/commands/git_commands/sync.go
index c56422029..dc0a0c68c 100644
--- a/pkg/commands/git_commands/sync.go
+++ b/pkg/commands/git_commands/sync.go
@@ -54,7 +54,9 @@ type FetchOptions struct {
// Fetch fetch git repo
func (self *SyncCommands) FetchCmdObj(opts FetchOptions) oscommands.ICmdObj {
- cmdArgs := NewGitCmd("fetch").ToArgv()
+ cmdArgs := NewGitCmd("fetch").
+ ArgIf(self.UserConfig.Git.FetchAll, "--all").
+ ToArgv()
cmdObj := self.cmd.New(cmdArgs)
if opts.Background {
diff --git a/pkg/commands/git_commands/sync_test.go b/pkg/commands/git_commands/sync_test.go
index 07fe8f932..f5eb0d403 100644
--- a/pkg/commands/git_commands/sync_test.go
+++ b/pkg/commands/git_commands/sync_test.go
@@ -95,15 +95,17 @@ func TestSyncPush(t *testing.T) {
func TestSyncFetch(t *testing.T) {
type scenario struct {
- testName string
- opts FetchOptions
- test func(oscommands.ICmdObj)
+ testName string
+ opts FetchOptions
+ fetchAllConfig bool
+ test func(oscommands.ICmdObj)
}
scenarios := []scenario{
{
- testName: "Fetch in foreground",
- opts: FetchOptions{Background: false},
+ 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)
@@ -111,20 +113,42 @@ func TestSyncFetch(t *testing.T) {
},
},
{
- testName: "Fetch in background",
- opts: FetchOptions{Background: true},
+ 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))
})
}