Skip to content

Commit d04f81a

Browse files
agrntechknowlogick
authored andcommitted
GetCommit() returns a ErrNotExist if short commit ID does not exists (go-gitea#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 <[email protected]> * 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 <[email protected]>
1 parent 49292ad commit d04f81a

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
@@ -140,6 +140,9 @@ func (repo *Repository) GetCommit(commitID string) (*Commit, error) {
140140
var err error
141141
commitID, err = NewCommand("rev-parse", commitID).RunInDir(repo.Path)
142142
if err != nil {
143+
if strings.Contains(err.Error(), "unknown revision or path") {
144+
return nil, ErrNotExist{commitID, ""}
145+
}
143146
return nil, err
144147
}
145148
}

0 commit comments

Comments
 (0)