Allow client fetch to use insecure credentials pattern

This commit is contained in:
William Martin 2024-11-26 22:08:45 +01:00
parent 7affcadb5e
commit 6b7f1ff060
6 changed files with 8 additions and 47 deletions

View file

@ -577,16 +577,11 @@ func (c *Client) AddRemote(ctx context.Context, name, urlStr string, trackingBra
// Below are commands that make network calls and need authentication credentials supplied from gh.
func (c *Client) Fetch(ctx context.Context, remote string, refspec string, mods ...CommandModifier) error {
host, err := c.CredentialPatternFromRemote(ctx, remote)
if err != nil {
return err
}
args := []string{"fetch", remote}
if refspec != "" {
args = append(args, refspec)
}
cmd, err := c.AuthenticatedCommand(ctx, host, args...)
cmd, err := c.AuthenticatedCommand(ctx, InsecureAllMatchingCredentialsPattern, args...)
if err != nil {
return err
}

View file

@ -1166,33 +1166,15 @@ func TestClientFetch(t *testing.T) {
name: "accepts command modifiers",
mods: []CommandModifier{WithRepoDir("/path/to/repo")},
commands: map[args]commandResult{
`path/to/git remote get-url origin`: {
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 fetch origin trunk`: {
`path/to/git -C /path/to/repo -c credential.helper= -c credential.helper=!"gh" auth git-credential fetch origin trunk`: {
ExitStatus: 0,
},
},
},
{
name: "git error on get-url",
commands: map[args]commandResult{
`path/to/git remote get-url origin`: {
ExitStatus: 1,
Stderr: "get-url 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 fetch origin trunk`: {
`path/to/git -c credential.helper= -c credential.helper=!"gh" auth git-credential fetch origin trunk`: {
ExitStatus: 1,
Stderr: "fetch error message",
},
@ -1237,10 +1219,6 @@ func TestClientPull(t *testing.T) {
name: "accepts command modifiers",
mods: []CommandModifier{WithRepoDir("/path/to/repo")},
commands: map[args]commandResult{
`path/to/git remote get-url origin`: {
ExitStatus: 0,
Stdout: "https://github.com/cli/nonexistent.git",
},
`path/to/git -C /path/to/repo -c credential.helper= -c credential.helper=!"gh" auth git-credential pull --ff-only origin trunk`: {
ExitStatus: 0,
},