GetCommit() returns a ErrNotExist if short commit ID does not exists (#113)

* 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>

* GetCommit(): change the comparison for short commit messages

`fatal: ambiguous argument` can be the beginning of two errors in
git. This changes the comparison to something less ambiguous.

Signed-off-by: Alban Gruin <alban@pa1ch.fr>
This commit is contained in:
agrn
2019-02-03 04:21:49 +01:00
committed by techknowlogick
parent 49292ad1fb
commit d04f81a6f8
+3
View File
@@ -140,6 +140,9 @@ func (repo *Repository) GetCommit(commitID string) (*Commit, error) {
var err error
commitID, err = NewCommand("rev-parse", commitID).RunInDir(repo.Path)
if err != nil {
if strings.Contains(err.Error(), "unknown revision or path") {
return nil, ErrNotExist{commitID, ""}
}
return nil, err
}
}