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)
| 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.). |
| 364 | func 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. |
| 392 | func revParseCommit(repoDir, repoRef string) (string, error) { |
no test coverage detected