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

Function RevParseRepoRef

pkgs/git/local.go:364–389  ·  view source on GitHub ↗

RevParseRepoRef return full commit hash with repo ref, if repo ref is not found in remote, then find it in local repo, the ref can be any valid git revision (branch, tag, HEAD, commit hash, etc.).

(ctx context.Context, nameVersion, repoDir, repoRef string)

Source from the content-addressed store, hash-verified

362// RevParseRepoRef return full commit hash with repo ref, if repo ref is not found in remote,
363// then find it in local repo, the ref can be any valid git revision (branch, tag, HEAD, commit hash, etc.).
364func RevParseRepoRef(ctx context.Context, nameVersion, repoDir, repoRef string) (string, error) {
365 repoRef = strings.TrimSpace(repoRef)
366 if repoRef == "" {
367 return "", nil
368 }
369
370 // Prefer remote branch heads when the expected ref names a branch.
371 if !ctx.Offline() {
372 remoteName, err := getPrimaryRemote(repoDir)
373 if err != nil {
374 return "", err
375 }
376 if remoteName != "" {
377 // Fetch the specific remote ref to ensure we can resolve it.
378 if err := fetchRemoteRef(nameVersion, repoDir, remoteName, repoRef); err != nil {
379 return "", err
380 }
381 if remoteCommit, err := revParseCommit(repoDir, remoteName+"/"+repoRef); err == nil {
382 return remoteCommit, nil
383 }
384 }
385 }
386
387 // Fall back to any locally resolvable ref: commit hash, tag, branch, etc.
388 return revParseCommit(repoDir, repoRef)
389}
390
391// revParseCommit returns the full commit hash for the given repo ref.
392func revParseCommit(repoDir, repoRef string) (string, error) {

Callers 1

CheckIfRefMatchesFunction · 0.85

Calls 4

getPrimaryRemoteFunction · 0.85
fetchRemoteRefFunction · 0.85
revParseCommitFunction · 0.85
OfflineMethod · 0.65

Tested by

no test coverage detected