repo/commit: improve error detection

Response 404 not 500 for raw diff if object does not exist.
This commit is contained in:
Unknwon
2017-04-04 02:01:29 -04:00
parent 55afc1ad21
commit 41c8e87be8
3 changed files with 13 additions and 10 deletions

View File

@@ -106,7 +106,7 @@ func (repo *Repository) getCommit(id sha1) (*Commit, error) {
data, err := NewCommand("cat-file", "-p", id.String()).RunInDirBytes(repo.Path)
if err != nil {
if strings.Contains(err.Error(), "fatal: Not a valid object name") {
if strings.Contains(err.Error(), "exit status 128") {
return nil, ErrNotExist{id.String(), ""}
}
return nil, err
@@ -129,6 +129,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(), "exit status 128") {
return nil, ErrNotExist{commitID, ""}
}
return nil, err
}
}