| 75 | } |
| 76 | |
| 77 | func (c *Client) Command(ctx context.Context, args ...string) (*Command, error) { |
| 78 | if c.RepoDir != "" { |
| 79 | args = append([]string{"-C", c.RepoDir}, args...) |
| 80 | } |
| 81 | commandContext := exec.CommandContext |
| 82 | if c.commandContext != nil { |
| 83 | commandContext = c.commandContext |
| 84 | } |
| 85 | var err error |
| 86 | c.mu.Lock() |
| 87 | if c.GitPath == "" { |
| 88 | c.GitPath, err = resolveGitPath() |
| 89 | } |
| 90 | c.mu.Unlock() |
| 91 | if err != nil { |
| 92 | return nil, err |
| 93 | } |
| 94 | cmd := commandContext(ctx, c.GitPath, args...) |
| 95 | cmd.Stderr = c.Stderr |
| 96 | cmd.Stdin = c.Stdin |
| 97 | cmd.Stdout = c.Stdout |
| 98 | return &Command{cmd}, nil |
| 99 | } |
| 100 | |
| 101 | // CredentialPattern is used to inform AuthenticatedCommand which patterns Git should match |
| 102 | // against when trying to find credentials. It is a little over-engineered as a type because we |