MCPcopy Create free account
hub / github.com/celer-pkg/celer / GetRemoteHeadCommit

Function GetRemoteHeadCommit

pkgs/git/remote.go:41–55  ·  view source on GitHub ↗

GetRemoteHeadCommit resolves the HEAD commit of a remote repository.

(target, repoUrl string)

Source from the content-addressed store, hash-verified

39
40// GetRemoteHeadCommit resolves the HEAD commit of a remote repository.
41func 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.
58func GetRemoteRefCommit(target, repoUrl, repoRef string) (string, error) {

Callers 1

resolveGitRefFunction · 0.92

Calls 4

NewExecutorFunction · 0.92
SprintfMethod · 0.80
ExecuteOutputMethod · 0.80
WithRetryMethod · 0.80

Tested by

no test coverage detected