Skip to content

Commit

Permalink
Add test for git-notes
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberShadow committed May 22, 2019
1 parent fde0b98 commit b20bf0a
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 2 deletions.
6 changes: 5 additions & 1 deletion modules/git/notes.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (
"gopkg.in/src-d/go-git.v4/plumbing"
)

// NotesRef is the git ref where Gitea will look for git-notes data.
// The value ("refs/notes/commits") is the default ref used by git-notes.
const NotesRef = "refs/notes/commits"

// Note stores information about a note created using git-notes.
type Note struct {
Message []byte
Expand All @@ -18,7 +22,7 @@ type Note struct {

// GetNote retrieves the git-notes data for a given commit.
func GetNote(repo *Repository, commitID string, note *Note) error {
notes, err := repo.GetCommit("refs/notes/commits")
notes, err := repo.GetCommit(NotesRef)
if err != nil {
return err
}
Expand Down
24 changes: 24 additions & 0 deletions modules/git/notes_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2019 The Gitea Authors. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.

package git

import (
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
)

func TestGetNotes(t *testing.T) {
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
bareRepo1, err := OpenRepository(bareRepo1Path)
assert.NoError(t, err)

note := Note{}
err = GetNote(bareRepo1, "95bb4d39648ee7e325106df01a621c530863a653", &note)
assert.NoError(t, err)
assert.Equal(t, []byte("Note contents\n"), note.Message)
assert.Equal(t, "Vladimir Panteleev", note.Commit.Author.Name)
}
3 changes: 2 additions & 1 deletion modules/git/repo_ref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ func TestRepository_GetRefs(t *testing.T) {
refs, err := bareRepo1.GetRefs()

assert.NoError(t, err)
assert.Len(t, refs, 4)
assert.Len(t, refs, 5)

expectedRefs := []string{
BranchPrefix + "branch1",
BranchPrefix + "branch2",
BranchPrefix + "master",
TagPrefix + "test",
NotesRef,
}

for _, ref := range refs {
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
x��M
�0F]���B�&&m"�@\�Of�6�HG����
~˷x��y���� ��?[����B�&
H<b�yߙNGt��ڨ��~.�"�1x�Ix`����&=㚸,}��{�X���� �p��)���j�}^ 1AZ����3�,����I0
1 change: 1 addition & 0 deletions modules/git/tests/repos/repo1_bare/refs/notes/commits
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ca6b5ddf303169a72d2a2971acde4f6eea194e5c

0 comments on commit b20bf0a

Please sign in to comment.