Skip to content

Commit 1f1117c

Browse files
odinugeunknwon
authored andcommitted
Add support for abbreviated commit IDs (#10)
Support shorter commit IDs than 40 characters
1 parent 0888f00 commit 1f1117c

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

repo_commit.go

+7
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,13 @@ func (repo *Repository) getCommit(id sha1) (*Commit, error) {
110110

111111
// GetCommit returns commit object of by ID string.
112112
func (repo *Repository) GetCommit(commitID string) (*Commit, error) {
113+
if len(commitID) != 40 {
114+
var err error
115+
commitID, err = NewCommand("rev-parse", commitID).RunInDir(repo.Path)
116+
if err != nil {
117+
return nil, err
118+
}
119+
}
113120
id, err := NewIDFromString(commitID)
114121
if err != nil {
115122
return nil, err

0 commit comments

Comments
 (0)