Hash returns the commit hash for the given ref. Returns ErrRefNotFound if the ref does not resolve.
(ctx context.Context, path, ref string)
| 200 | |
| 201 | // Hash returns the commit hash for the given ref. Returns ErrRefNotFound if the ref does not resolve. |
| 202 | func Hash(ctx context.Context, path, ref string) (string, error) { |
| 203 | out, err := Run(ctx, path, "rev-parse", "--verify", ref) |
| 204 | if err != nil { |
| 205 | if strings.Contains(err.Error(), "Needed a single revision") { |
| 206 | return "", ErrRefNotFound |
| 207 | } |
| 208 | return "", err |
| 209 | } |
| 210 | return out, nil |
| 211 | } |
| 212 | |
| 213 | // Run executes a git command with the specified arguments in the given path and returns its output or an error. |
| 214 | // If path is empty, the command runs without -C (use for commands like `clone` that take an explicit destination). |