]> source.dussan.org Git - gitea.git/commitdiff
Change the implementation of the go-git version of GetNote to mirror the non go-git...
authornitul1991 <nitul1991@users.noreply.github.com>
Mon, 9 Aug 2021 15:24:34 +0000 (20:54 +0530)
committerGitHub <noreply@github.com>
Mon, 9 Aug 2021 15:24:34 +0000 (16:24 +0100)
Fixes #16657

modules/git/notes_gogit.go
modules/git/notes_test.go

index 534a5d517153a603f195b41773a7399d83f7ac4a..702754069bd3a61cee06aa56c8b98ef009d7f0a0 100644 (file)
@@ -36,6 +36,9 @@ func GetNote(ctx context.Context, repo *Repository, commitID string, note *Note)
                        remainingCommitID = remainingCommitID[2:]
                }
                if err != nil {
+                       if err == object.ErrDirectoryNotFound {
+                               return ErrNotExist{ID: remainingCommitID, RelPath: path}
+                       }
                        return err
                }
        }
index f66a191e6ae2758da841031a85e4a6b6207e22a5..fec46e5960fb5ecc5386d35aed035b960f0db07b 100644 (file)
@@ -39,3 +39,15 @@ func TestGetNestedNotes(t *testing.T) {
        assert.NoError(t, err)
        assert.Equal(t, []byte("Note 1"), note.Message)
 }
+
+func TestGetNonExistentNotes(t *testing.T) {
+       bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
+       bareRepo1, err := OpenRepository(bareRepo1Path)
+       assert.NoError(t, err)
+       defer bareRepo1.Close()
+
+       note := Note{}
+       err = GetNote(context.Background(), bareRepo1, "non_existent_sha", &note)
+       assert.Error(t, err)
+       assert.IsType(t, ErrNotExist{}, err)
+}