| 59 | } |
| 60 | |
| 61 | func (cli *GitCLI) RemoteURL(ctx context.Context) (string, error) { |
| 62 | // Try default remote based on remote tracking branch. |
| 63 | if remote, err := cli.currentRemote(ctx); err == nil && remote != "" { |
| 64 | if ru, err := cli.clean(cli.Run(ctx, "remote", "get-url", remote)); err == nil && ru != "" { |
| 65 | return bkurlutil.RedactCredentials(ru), nil |
| 66 | } |
| 67 | } |
| 68 | // Next try to get the remote URL from the origin remote first. |
| 69 | if ru, err := cli.clean(cli.Run(ctx, "remote", "get-url", "origin")); err == nil && ru != "" { |
| 70 | return bkurlutil.RedactCredentials(ru), nil |
| 71 | } |
| 72 | // If that fails, try to get the remote URL from the upstream remote. |
| 73 | if ru, err := cli.clean(cli.Run(ctx, "remote", "get-url", "upstream")); err == nil && ru != "" { |
| 74 | return bkurlutil.RedactCredentials(ru), nil |
| 75 | } |
| 76 | return "", errors.New("no remote URL found for either origin or upstream") |
| 77 | } |
| 78 | |
| 79 | func (cli *GitCLI) FullCommit(ctx context.Context) (string, error) { |
| 80 | return cli.clean(cli.Run(ctx, "show", "--format=%H", "HEAD", "--quiet", "--")) |