GetHash retrieves the current HEADs hash
(ctx context.Context, localPath string)
| 34 | |
| 35 | // GetHash retrieves the current HEADs hash |
| 36 | func GetHash(ctx context.Context, localPath string) (string, error) { |
| 37 | repo, err := git.PlainOpen(localPath) |
| 38 | if err != nil { |
| 39 | // last resort, try with cli |
| 40 | if isGitCommandAvailable(ctx) { |
| 41 | out, err := command.CombinedOutput(ctx, localPath, expand.ListEnviron(os.Environ()...), "git", "rev-parse", "HEAD") |
| 42 | if err != nil { |
| 43 | return "", errors.Errorf("Error running 'git rev-parse HEAD': %v -> %s", err, string(out)) |
| 44 | } |
| 45 | |
| 46 | return strings.TrimSpace(string(out)), nil |
| 47 | } |
| 48 | |
| 49 | return "", errors.Wrap(err, "git open") |
| 50 | } |
| 51 | |
| 52 | head, err := repo.Head() |
| 53 | if err != nil { |
| 54 | return "", errors.Wrap(err, "get head") |
| 55 | } |
| 56 | |
| 57 | return head.Hash().String(), nil |
| 58 | } |
| 59 | |
| 60 | // GetRemote retrieves the remote origin |
| 61 | func GetRemote(localPath string) (string, error) { |