Skip to content

Commit b20bf0a

Browse files
committed
Add test for git-notes
1 parent fde0b98 commit b20bf0a

File tree

7 files changed

+36
-2
lines changed

7 files changed

+36
-2
lines changed

modules/git/notes.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import (
1010
"gopkg.in/src-d/go-git.v4/plumbing"
1111
)
1212

13+
// NotesRef is the git ref where Gitea will look for git-notes data.
14+
// The value ("refs/notes/commits") is the default ref used by git-notes.
15+
const NotesRef = "refs/notes/commits"
16+
1317
// Note stores information about a note created using git-notes.
1418
type Note struct {
1519
Message []byte
@@ -18,7 +22,7 @@ type Note struct {
1822

1923
// GetNote retrieves the git-notes data for a given commit.
2024
func GetNote(repo *Repository, commitID string, note *Note) error {
21-
notes, err := repo.GetCommit("refs/notes/commits")
25+
notes, err := repo.GetCommit(NotesRef)
2226
if err != nil {
2327
return err
2428
}

modules/git/notes_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2019 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package git
6+
7+
import (
8+
"path/filepath"
9+
"testing"
10+
11+
"github.com/stretchr/testify/assert"
12+
)
13+
14+
func TestGetNotes(t *testing.T) {
15+
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
16+
bareRepo1, err := OpenRepository(bareRepo1Path)
17+
assert.NoError(t, err)
18+
19+
note := Note{}
20+
err = GetNote(bareRepo1, "95bb4d39648ee7e325106df01a621c530863a653", &note)
21+
assert.NoError(t, err)
22+
assert.Equal(t, []byte("Note contents\n"), note.Message)
23+
assert.Equal(t, "Vladimir Panteleev", note.Commit.Author.Name)
24+
}

modules/git/repo_ref_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ func TestRepository_GetRefs(t *testing.T) {
1919
refs, err := bareRepo1.GetRefs()
2020

2121
assert.NoError(t, err)
22-
assert.Len(t, refs, 4)
22+
assert.Len(t, refs, 5)
2323

2424
expectedRefs := []string{
2525
BranchPrefix + "branch1",
2626
BranchPrefix + "branch2",
2727
BranchPrefix + "master",
2828
TagPrefix + "test",
29+
NotesRef,
2930
}
3031

3132
for _, ref := range refs {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
x��M
2+
�0F]���B�&&m"�@\�Of�6�HG����
3+
~˷x��y���� ��?[����B�&
4+
H<b�yߙNGt��ڨ��~.�"�1x�Ix`����&=㚸,}��{�X���� �p��)���j�}^ 1AZ����3�,����I0
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ca6b5ddf303169a72d2a2971acde4f6eea194e5c

0 commit comments

Comments
 (0)