validateCommit checks if the given commit reference exists in the repository
(repoPath, commitID string)
| 76 | |
| 77 | // validateCommit checks if the given commit reference exists in the repository |
| 78 | func validateCommit(repoPath, commitID string) error { |
| 79 | if err := validateGitRef(commitID); err != nil { |
| 80 | return err |
| 81 | } |
| 82 | |
| 83 | _, stderr, err := runGitCommand(repoPath, "rev-parse", "--verify", commitID+"^{commit}") |
| 84 | if err != nil { |
| 85 | if stderr != "" { |
| 86 | return fmt.Errorf("invalid commit reference '%s': %s", commitID, stderr) |
| 87 | } |
| 88 | return fmt.Errorf("invalid commit reference '%s'", commitID) |
| 89 | } |
| 90 | |
| 91 | return nil |
| 92 | } |
| 93 | |
| 94 | // GetCurrentCommitHash returns the current commit hash (HEAD) |
| 95 | func GetCurrentCommitHash(repoPath string) (string, error) { |
no test coverage detected