Allow client pull to use insecure credential pattern

This commit is contained in:
William Martin 2024-11-26 21:50:19 +01:00
parent 5f5c5270c9
commit 75712de712
5 changed files with 11 additions and 45 deletions

View file

@ -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
}

View file

@ -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",

View file

@ -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 {

View file

@ -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",

View file

@ -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{