GetRemoteHeadCommit resolves the HEAD commit of a remote repository.
(target, repoUrl string)
| 39 | |
| 40 | // GetRemoteHeadCommit resolves the HEAD commit of a remote repository. |
| 41 | func GetRemoteHeadCommit(target, repoUrl string) (string, error) { |
| 42 | title := fmt.Sprintf("[resolve remote HEAD: %s]", target) |
| 43 | output, err := cmd.NewExecutor(title, "git", "ls-remote", repoUrl, "HEAD"). |
| 44 | WithRetry(retryMaxAttempts).ExecuteOutput() |
| 45 | if err != nil { |
| 46 | return "", fmt.Errorf("failed to resolve HEAD of %s -> %w", repoUrl, err) |
| 47 | } |
| 48 | |
| 49 | fields := strings.Fields(output) |
| 50 | if len(fields) < 1 { |
| 51 | return "", fmt.Errorf("no HEAD commit found for %s", repoUrl) |
| 52 | } |
| 53 | |
| 54 | return fields[0], nil |
| 55 | } |
| 56 | |
| 57 | // GetRemoteRefCommit read remote git commit hash of specified ref. |
| 58 | func GetRemoteRefCommit(target, repoUrl, repoRef string) (string, error) { |
no test coverage detected