From 1f1117c3969f53809bb09f6da07ec2493b2aa07f Mon Sep 17 00:00:00 2001 From: Odin Ugedal Date: Fri, 3 Jun 2016 03:16:23 +0200 Subject: [PATCH] Add support for abbreviated commit IDs (#10) Support shorter commit IDs than 40 characters --- repo_commit.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/repo_commit.go b/repo_commit.go index 286561bc54d91..13a77f990cebb 100644 --- a/repo_commit.go +++ b/repo_commit.go @@ -110,6 +110,13 @@ func (repo *Repository) getCommit(id sha1) (*Commit, error) { // GetCommit returns commit object of by ID string. func (repo *Repository) GetCommit(commitID string) (*Commit, error) { + if len(commitID) != 40 { + var err error + commitID, err = NewCommand("rev-parse", commitID).RunInDir(repo.Path) + if err != nil { + return nil, err + } + } id, err := NewIDFromString(commitID) if err != nil { return nil, err