diff --git a/git/client.go b/git/client.go index 8a8159134..658fb40cd 100644 --- a/git/client.go +++ b/git/client.go @@ -597,16 +597,11 @@ func (c *Client) Fetch(ctx context.Context, remote string, refspec string, mods } func (c *Client) Pull(ctx context.Context, remote, branch string, mods ...CommandModifier) error { - host, err := c.CredentialPatternFromRemote(ctx, remote) - if err != nil { - return err - } - args := []string{"pull", "--ff-only"} if remote != "" && branch != "" { args = append(args, remote, branch) } - cmd, err := c.AuthenticatedCommand(ctx, host, args...) + cmd, err := c.AuthenticatedCommand(ctx, InsecureAllMatchingCredentialsPattern, args...) if err != nil { return err } diff --git a/git/client_test.go b/git/client_test.go index cf9abc54c..d48a6af08 100644 --- a/git/client_test.go +++ b/git/client_test.go @@ -1157,11 +1157,7 @@ func TestClientFetch(t *testing.T) { { name: "fetch", commands: map[args]commandResult{ - `path/to/git remote get-url origin`: { - ExitStatus: 0, - Stdout: "https://github.com/cli/nonexistent.git", - }, - `path/to/git -c credential.https://github.com.helper= -c credential.https://github.com.helper=!"gh" auth git-credential fetch origin trunk`: { + `path/to/git -c credential.helper= -c credential.helper=!"gh" auth git-credential fetch origin trunk`: { ExitStatus: 0, }, }, @@ -1232,11 +1228,7 @@ func TestClientPull(t *testing.T) { { name: "pull", commands: map[args]commandResult{ - `path/to/git remote get-url origin`: { - ExitStatus: 0, - Stdout: "https://github.com/cli/nonexistent.git", - }, - `path/to/git -c credential.https://github.com.helper= -c credential.https://github.com.helper=!"gh" auth git-credential pull --ff-only origin trunk`: { + `path/to/git -c credential.helper= -c credential.helper=!"gh" auth git-credential pull --ff-only origin trunk`: { ExitStatus: 0, }, }, @@ -1249,34 +1241,20 @@ func TestClientPull(t *testing.T) { ExitStatus: 0, Stdout: "https://github.com/cli/nonexistent.git", }, - `path/to/git -C /path/to/repo -c credential.https://github.com.helper= -c credential.https://github.com.helper=!"gh" auth git-credential pull --ff-only origin trunk`: { + `path/to/git -C /path/to/repo -c credential.helper= -c credential.helper=!"gh" auth git-credential pull --ff-only origin trunk`: { ExitStatus: 0, }, }, }, { - name: "git error on get-url", + name: "git error on pull", commands: map[args]commandResult{ - `path/to/git remote get-url origin`: { + `path/to/git -c credential.helper= -c credential.helper=!"gh" auth git-credential pull --ff-only origin trunk`: { ExitStatus: 1, - Stderr: "get-url error message", + Stderr: "pull error message", }, }, - wantErrorMsg: "failed to run git: get-url error message", - }, - { - name: "git error on fetch", - commands: map[args]commandResult{ - `path/to/git remote get-url origin`: { - ExitStatus: 0, - Stdout: "https://github.com/cli/nonexistent.git", - }, - `path/to/git -c credential.https://github.com.helper= -c credential.https://github.com.helper=!"gh" auth git-credential pull --ff-only origin trunk`: { - ExitStatus: 1, - Stderr: "fetch error message", - }, - }, - wantErrorMsg: "failed to run git: fetch error message", + wantErrorMsg: "failed to run git: pull error message", }, } @@ -1348,7 +1326,7 @@ func TestClientPush(t *testing.T) { }, `path/to/git -c credential.https://github.com.helper= -c credential.https://github.com.helper=!"gh" auth git-credential push --set-upstream origin trunk`: { ExitStatus: 1, - Stderr: "fetch error message", + Stderr: "push error message", }, }, wantErrorMsg: "failed to run git: fetch error message", diff --git a/internal/run/stub.go b/internal/run/stub.go index 9499da8e2..5cd3c6de5 100644 --- a/internal/run/stub.go +++ b/internal/run/stub.go @@ -9,7 +9,7 @@ import ( ) const ( - gitAuthRE = `-c credential\..+\.helper= -c credential\..+\.helper=!"[^"]+" auth git-credential ` + gitAuthRE = `-c credential(?:\..+)?\.helper= -c credential(?:\..+)?\.helper=!"[^"]+" auth git-credential ` ) type T interface { diff --git a/pkg/cmd/issue/develop/develop_test.go b/pkg/cmd/issue/develop/develop_test.go index 28642eb51..655668b46 100644 --- a/pkg/cmd/issue/develop/develop_test.go +++ b/pkg/cmd/issue/develop/develop_test.go @@ -314,7 +314,7 @@ func TestDevelopRun(t *testing.T) { ) }, runStubs: func(cs *run.CommandStubber) { - cs.Register(`git remote get-url origin`, 0, "https://github.com/cli/cli.git") + cs.Register(`git remote get-url origin`, 0, "https://github.com/OWNER/REPO.git") cs.Register(`git fetch origin \+refs/heads/my-issue-1:refs/remotes/origin/my-issue-1`, 0, "") }, expectedOut: "github.com/OWNER/REPO/tree/my-issue-1\n", @@ -474,7 +474,6 @@ func TestDevelopRun(t *testing.T) { cs.Register(`git fetch origin \+refs/heads/my-branch:refs/remotes/origin/my-branch`, 0, "") cs.Register(`git rev-parse --verify refs/heads/my-branch`, 0, "") cs.Register(`git checkout my-branch`, 0, "") - cs.Register(`git remote get-url origin`, 0, "https://github.com/cli/cli.git") cs.Register(`git pull --ff-only origin my-branch`, 0, "") }, expectedOut: "github.com/OWNER/REPO/tree/my-branch\n", diff --git a/pkg/cmd/pr/merge/merge_test.go b/pkg/cmd/pr/merge/merge_test.go index ff9f6ef5e..21df882b4 100644 --- a/pkg/cmd/pr/merge/merge_test.go +++ b/pkg/cmd/pr/merge/merge_test.go @@ -644,7 +644,6 @@ func TestPrMerge_deleteBranch(t *testing.T) { cs.Register(`git checkout main`, 0, "") cs.Register(`git rev-parse --verify refs/heads/blueberries`, 0, "") cs.Register(`git branch -D blueberries`, 0, "") - cs.Register(`git remote get-url origin`, 0, "https://github.com/OWNER/REPO.git") cs.Register(`git pull --ff-only`, 0, "") output, err := runCommand(http, nil, "blueberries", true, `pr merge --merge --delete-branch`) @@ -696,7 +695,6 @@ func TestPrMerge_deleteBranch_nonDefault(t *testing.T) { cs.Register(`git checkout fruit`, 0, "") cs.Register(`git rev-parse --verify refs/heads/blueberries`, 0, "") cs.Register(`git branch -D blueberries`, 0, "") - cs.Register(`git remote get-url origin`, 0, "https://github.com/OWNER/REPO.git") cs.Register(`git pull --ff-only`, 0, "") output, err := runCommand(http, nil, "blueberries", true, `pr merge --merge --delete-branch`) @@ -746,7 +744,6 @@ func TestPrMerge_deleteBranch_onlyLocally(t *testing.T) { cs.Register(`git checkout main`, 0, "") cs.Register(`git rev-parse --verify refs/heads/blueberries`, 0, "") cs.Register(`git branch -D blueberries`, 0, "") - cs.Register(`git remote get-url origin`, 0, "https://github.com/OWNER/REPO.git") cs.Register(`git pull --ff-only`, 0, "") output, err := runCommand(http, nil, "blueberries", true, `pr merge --merge --delete-branch`) @@ -797,7 +794,6 @@ func TestPrMerge_deleteBranch_checkoutNewBranch(t *testing.T) { cs.Register(`git checkout -b fruit --track origin/fruit`, 0, "") cs.Register(`git rev-parse --verify refs/heads/blueberries`, 0, "") cs.Register(`git branch -D blueberries`, 0, "") - cs.Register(`git remote get-url origin`, 0, "https://github.com/OWNER/REPO.git") cs.Register(`git pull --ff-only`, 0, "") output, err := runCommand(http, nil, "blueberries", true, `pr merge --merge --delete-branch`) @@ -1085,7 +1081,6 @@ func TestPrMerge_alreadyMerged(t *testing.T) { cs.Register(`git checkout main`, 0, "") cs.Register(`git rev-parse --verify refs/heads/blueberries`, 0, "") cs.Register(`git branch -D blueberries`, 0, "") - cs.Register(`git remote get-url origin`, 0, "https://github.com/OWNER/REPO.git") cs.Register(`git pull --ff-only`, 0, "") pm := &prompter.PrompterMock{ @@ -1329,7 +1324,6 @@ func TestPRMergeTTY_withDeleteBranch(t *testing.T) { cs.Register(`git checkout main`, 0, "") cs.Register(`git rev-parse --verify refs/heads/blueberries`, 0, "") cs.Register(`git branch -D blueberries`, 0, "") - cs.Register(`git remote get-url origin`, 0, "https://github.com/OWNER/REPO.git") cs.Register(`git pull --ff-only`, 0, "") pm := &prompter.PrompterMock{