mirror of
https://github.com/go-gitea/git.git
synced 2026-02-05 15:45:40 +01:00
Fix for bad commitID to show up in error (#148)
* Fix for bad commitID to show up in error * Adds test for repo_commit GetCommit * Adds test if commitID is valid branch
This commit is contained in:
committed by
techknowlogick
parent
8983773ac6
commit
6cba05a150
@@ -153,13 +153,14 @@ func (repo *Repository) getCommit(id SHA1) (*Commit, error) {
|
|||||||
func (repo *Repository) GetCommit(commitID string) (*Commit, error) {
|
func (repo *Repository) GetCommit(commitID string) (*Commit, error) {
|
||||||
if len(commitID) != 40 {
|
if len(commitID) != 40 {
|
||||||
var err error
|
var err error
|
||||||
commitID, err = NewCommand("rev-parse", commitID).RunInDir(repo.Path)
|
actualCommitID, err := NewCommand("rev-parse", commitID).RunInDir(repo.Path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if strings.Contains(err.Error(), "unknown revision or path") {
|
if strings.Contains(err.Error(), "unknown revision or path") {
|
||||||
return nil, ErrNotExist{commitID, ""}
|
return nil, ErrNotExist{commitID, ""}
|
||||||
}
|
}
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
commitID = actualCommitID
|
||||||
}
|
}
|
||||||
id, err := NewIDFromString(commitID)
|
id, err := NewIDFromString(commitID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ func TestRepository_GetCommitBranches(t *testing.T) {
|
|||||||
{"37991dec2c8e592043f47155ce4808d4580f9123", []string{"master"}},
|
{"37991dec2c8e592043f47155ce4808d4580f9123", []string{"master"}},
|
||||||
{"95bb4d39648ee7e325106df01a621c530863a653", []string{"branch1", "branch2"}},
|
{"95bb4d39648ee7e325106df01a621c530863a653", []string{"branch1", "branch2"}},
|
||||||
{"8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2", []string{"branch2", "master"}},
|
{"8d92fc957a4d7cfd98bc375f0b7bb189a0d6c9f2", []string{"branch2", "master"}},
|
||||||
|
{"master", []string{"master"}},
|
||||||
}
|
}
|
||||||
for _, testCase := range testCases {
|
for _, testCase := range testCases {
|
||||||
commit, err := bareRepo1.GetCommit(testCase.CommitID)
|
commit, err := bareRepo1.GetCommit(testCase.CommitID)
|
||||||
@@ -47,3 +48,12 @@ func TestGetTagCommitWithSignature(t *testing.T) {
|
|||||||
// test that signature is not in message
|
// test that signature is not in message
|
||||||
assert.Equal(t, "tag", commit.CommitMessage)
|
assert.Equal(t, "tag", commit.CommitMessage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetCommitWithBadCommitID(t *testing.T) {
|
||||||
|
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||||
|
bareRepo1, err := OpenRepository(bareRepo1Path)
|
||||||
|
commit, err := bareRepo1.GetCommit("bad_branch")
|
||||||
|
assert.Nil(t, commit)
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.EqualError(t, err, "object does not exist [id: bad_branch, rel_path: ]")
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user