mirror of
https://github.com/go-gitea/git.git
synced 2026-07-01 20:34:42 -04:00
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:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user