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