MCPcopy Index your code
hub / github.com/google/git-appraise / ResolveRefCommit

Method ResolveRefCommit

repository/git.go:225–244  ·  view source on GitHub ↗

ResolveRefCommit returns the commit pointed to by the given ref, which may be a remote ref. This differs from GetCommitHash which only works on exact matches, in that it will try to intelligently handle the scenario of a ref not existing locally, but being known to exist in a remote repo. This met

(ref string)

Source from the content-addressed store, hash-verified

223// reviewee, while GetCommitHash should be used when the encompassing command should only be
224// performed by the reviewee.
225func (repo *GitRepo) ResolveRefCommit(ref string) (string, error) {
226 if err := repo.VerifyGitRef(ref); err == nil {
227 return repo.GetCommitHash(ref)
228 }
229 if strings.HasPrefix(ref, "refs/heads/") {
230 // The ref is a branch. Check if it exists in exactly one remote
231 pattern := strings.Replace(ref, "refs/heads", "**", 1)
232 matchingOutput, err := repo.runGitCommand("for-each-ref", "--format=%(refname)", pattern)
233 if err != nil {
234 return "", err
235 }
236 matchingRefs := strings.Split(matchingOutput, "\n")
237 if len(matchingRefs) == 1 && matchingRefs[0] != "" {
238 // There is exactly one match
239 return repo.GetCommitHash(matchingRefs[0])
240 }
241 return "", fmt.Errorf("Unable to find a git ref matching the pattern %q", pattern)
242 }
243 return "", fmt.Errorf("Unknown git ref %q", ref)
244}
245
246// GetCommitMessage returns the message stored in the commit pointed to by the given ref.
247func (repo *GitRepo) GetCommitMessage(ref string) (string, error) {

Callers

nothing calls this directly

Calls 3

VerifyGitRefMethod · 0.95
GetCommitHashMethod · 0.95
runGitCommandMethod · 0.95

Tested by

no test coverage detected