1
0
mirror of https://github.com/go-gitea/git.git synced 2026-02-05 06:45:03 +01:00

Add function to resolve short commit ID to full SHA1 (#122)

* Add function to resolve short commit ID to full SHA1

* Add tests for GetFullCommitID
This commit is contained in:
Lauris BH
2018-06-12 12:45:55 +03:00
committed by GitHub
parent 31f4b8e8c8
commit 466ac2480d
2 changed files with 30 additions and 0 deletions

View File

@@ -274,3 +274,19 @@ func (c *Commit) GetSubModule(entryname string) (*SubModule, error) {
}
return nil, nil
}
// GetFullCommitID returns full length (40) of commit ID by given short SHA in a repository.
func GetFullCommitID(repoPath, shortID string) (string, error) {
if len(shortID) >= 40 {
return shortID, nil
}
commitID, err := NewCommand("rev-parse", shortID).RunInDir(repoPath)
if err != nil {
if strings.Contains(err.Error(), "exit status 128") {
return "", ErrNotExist{shortID, ""}
}
return "", err
}
return strings.TrimSpace(commitID), nil
}