Skip to content

Commit 734679f

Browse files
committed
add --fetch flag to git spr update command
commit-id:f176bf4b
1 parent c85920f commit 734679f

2 files changed

Lines changed: 51 additions & 6 deletions

File tree

cmd/spr/main.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,12 @@ VERSION: fork of {{.Version}}
195195
if c.IsSet("no-rebase") {
196196
cfg.User.NoRebase = c.Bool("no-rebase")
197197
}
198+
if c.IsSet("fetch") && c.IsSet("no-fetch") {
199+
return fmt.Errorf("cannot use both --fetch and --no-fetch")
200+
}
201+
if c.IsSet("fetch") {
202+
cfg.User.NoFetch = !c.Bool("fetch")
203+
}
198204
if c.IsSet("no-fetch") {
199205
cfg.User.NoFetch = c.Bool("no-fetch")
200206
}
@@ -229,12 +235,18 @@ VERSION: fork of {{.Version}}
229235
// layer ops so it is likely relied on as a feature by users at this point
230236
EnvVars: []string{"SPR_NOREBASE"},
231237
},
232-
&cli.BoolFlag{
233-
Name: "no-fetch",
234-
Aliases: []string{"nf"},
235-
Usage: "Disable fetch",
236-
EnvVars: []string{"SPR_NOFETCH"},
237-
},
238+
&cli.BoolFlag{
239+
Name: "fetch",
240+
Aliases: []string{"f"},
241+
Usage: "Enable fetch (overrides noFetch config)",
242+
EnvVars: []string{"SPR_FETCH"},
243+
},
244+
&cli.BoolFlag{
245+
Name: "no-fetch",
246+
Aliases: []string{"nf"},
247+
Usage: "Disable fetch",
248+
EnvVars: []string{"SPR_NOFETCH"},
249+
},
238250
},
239251
},
240252
{

spr/spr_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,39 @@ func testAmendInvalidInput(t *testing.T, sync bool) {
974974
})
975975
}
976976

977+
func TestSPRFetchOverridesNoFetchConfig(t *testing.T) {
978+
// Test that --fetch flag overrides noFetch config (sets NoFetch back to false)
979+
// This simulates: yaml has noFetch: true, user passes --fetch on CLI
980+
s, gitmock, githubmock, _, output := makeTestObjects(t, true)
981+
assert := require.New(t)
982+
ctx := context.Background()
983+
984+
// Start with NoFetch true (as if loaded from yaml config)
985+
s.config.User.NoFetch = true
986+
// Then override it back to false (as the --fetch flag would do)
987+
s.config.User.NoFetch = false
988+
989+
c1 := git.Commit{
990+
CommitID: "00000001",
991+
CommitHash: "c100000000000000000000000000000000000000",
992+
Subject: "test commit 1",
993+
}
994+
995+
// With NoFetch=false, fetch should run
996+
githubmock.ExpectGetInfo()
997+
gitmock.ExpectFetch()
998+
gitmock.ExpectLogAndRespond([]*git.Commit{&c1})
999+
gitmock.ExpectPushCommits([]*git.Commit{&c1})
1000+
githubmock.ExpectCreatePullRequest(c1, nil)
1001+
githubmock.ExpectUpdatePullRequest(c1, nil)
1002+
githubmock.ExpectGetInfo()
1003+
s.UpdatePullRequests(ctx, nil, nil)
1004+
assert.Equal("[vvvv] 1 : test commit 1\n", output.String())
1005+
gitmock.ExpectationsMet()
1006+
githubmock.ExpectationsMet()
1007+
output.Reset()
1008+
}
1009+
9771010
func uintptr(a uint) *uint {
9781011
return &a
9791012
}

0 commit comments

Comments
 (0)