Skip to content

Commit 23d438f

Browse files
authored
Change the implementation of the go-git version of GetNote to mirror the non go-git version when passed a non-existent commit (#16658)
Fixes #16657
1 parent 1dc41c4 commit 23d438f

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

modules/git/notes_gogit.go

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ func GetNote(ctx context.Context, repo *Repository, commitID string, note *Note)
3636
remainingCommitID = remainingCommitID[2:]
3737
}
3838
if err != nil {
39+
if err == object.ErrDirectoryNotFound {
40+
return ErrNotExist{ID: remainingCommitID, RelPath: path}
41+
}
3942
return err
4043
}
4144
}

modules/git/notes_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,15 @@ func TestGetNestedNotes(t *testing.T) {
3939
assert.NoError(t, err)
4040
assert.Equal(t, []byte("Note 1"), note.Message)
4141
}
42+
43+
func TestGetNonExistentNotes(t *testing.T) {
44+
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
45+
bareRepo1, err := OpenRepository(bareRepo1Path)
46+
assert.NoError(t, err)
47+
defer bareRepo1.Close()
48+
49+
note := Note{}
50+
err = GetNote(context.Background(), bareRepo1, "non_existent_sha", &note)
51+
assert.Error(t, err)
52+
assert.IsType(t, ErrNotExist{}, err)
53+
}

0 commit comments

Comments
 (0)