Skip to content
This repository was archived by the owner on Apr 12, 2019. It is now read-only.

Commit ceeb8f4

Browse files
committed
GetCommit() returns a ErrNotExist if short commit ID does not exists
Currently, GetCommit() returns a generic error if a short commit ID does not exists in a repository. When a commit is not found by git-rev-parse, it returns an errors which contains "fatal: ambiguous argument". GetCommit() now search if the error contains this string, and, if it does, returns an ErrNotExist. The idea is to allow commits to be accessed from gitea with a short commit ID. Without this change, it would return a 500 Internal Server Error when a short ID does not exists in the repository. Signed-off-by: Alban Gruin <alban@pa1ch.fr>
1 parent dac1986 commit ceeb8f4

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

repo_commit.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ func (repo *Repository) GetCommit(commitID string) (*Commit, error) {
125125
var err error
126126
commitID, err = NewCommand("rev-parse", commitID).RunInDir(repo.Path)
127127
if err != nil {
128+
if strings.Contains(err.Error(), "fatal: ambiguous argument") {
129+
return nil, ErrNotExist{commitID, ""}
130+
}
128131
return nil, err
129132
}
130133
}

0 commit comments

Comments
 (0)