From ae1791bd348b84130c57fb33c5eff1716c01a3e7 Mon Sep 17 00:00:00 2001 From: Eitan Date: Fri, 10 Apr 2026 18:45:21 +0000 Subject: [PATCH] add --fetch flag to git spr update command commit-id:f176bf4b --- cmd/spr/main.go | 24 ++++++++++++++++++------ spr/spr_test.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/cmd/spr/main.go b/cmd/spr/main.go index dece6055..1854d4a5 100644 --- a/cmd/spr/main.go +++ b/cmd/spr/main.go @@ -195,6 +195,12 @@ VERSION: fork of {{.Version}} if c.IsSet("no-rebase") { cfg.User.NoRebase = c.Bool("no-rebase") } + if c.IsSet("fetch") && c.IsSet("no-fetch") { + return fmt.Errorf("cannot use both --fetch and --no-fetch") + } + if c.IsSet("fetch") { + cfg.User.NoFetch = !c.Bool("fetch") + } if c.IsSet("no-fetch") { cfg.User.NoFetch = c.Bool("no-fetch") } @@ -229,12 +235,18 @@ VERSION: fork of {{.Version}} // layer ops so it is likely relied on as a feature by users at this point EnvVars: []string{"SPR_NOREBASE"}, }, - &cli.BoolFlag{ - Name: "no-fetch", - Aliases: []string{"nf"}, - Usage: "Disable fetch", - EnvVars: []string{"SPR_NOFETCH"}, - }, + &cli.BoolFlag{ + Name: "fetch", + Aliases: []string{"f"}, + Usage: "Enable fetch (overrides noFetch config)", + EnvVars: []string{"SPR_FETCH"}, + }, + &cli.BoolFlag{ + Name: "no-fetch", + Aliases: []string{"nf"}, + Usage: "Disable fetch", + EnvVars: []string{"SPR_NOFETCH"}, + }, }, }, { diff --git a/spr/spr_test.go b/spr/spr_test.go index 0530422c..0379ee70 100644 --- a/spr/spr_test.go +++ b/spr/spr_test.go @@ -974,6 +974,39 @@ func testAmendInvalidInput(t *testing.T, sync bool) { }) } +func TestSPRFetchOverridesNoFetchConfig(t *testing.T) { + // Test that --fetch flag overrides noFetch config (sets NoFetch back to false) + // This simulates: yaml has noFetch: true, user passes --fetch on CLI + s, gitmock, githubmock, _, output := makeTestObjects(t, true) + assert := require.New(t) + ctx := context.Background() + + // Start with NoFetch true (as if loaded from yaml config) + s.config.User.NoFetch = true + // Then override it back to false (as the --fetch flag would do) + s.config.User.NoFetch = false + + c1 := git.Commit{ + CommitID: "00000001", + CommitHash: "c100000000000000000000000000000000000000", + Subject: "test commit 1", + } + + // With NoFetch=false, fetch should run + githubmock.ExpectGetInfo() + gitmock.ExpectFetch() + gitmock.ExpectLogAndRespond([]*git.Commit{&c1}) + gitmock.ExpectPushCommits([]*git.Commit{&c1}) + githubmock.ExpectCreatePullRequest(c1, nil) + githubmock.ExpectUpdatePullRequest(c1, nil) + githubmock.ExpectGetInfo() + s.UpdatePullRequests(ctx, nil, nil) + assert.Equal("[vvvv] 1 : test commit 1\n", output.String()) + gitmock.ExpectationsMet() + githubmock.ExpectationsMet() + output.Reset() +} + func uintptr(a uint) *uint { return &a }