From b20bf0a111948846966b3f2c71ab9ffcc67fb49c Mon Sep 17 00:00:00 2001 From: Vladimir Panteleev Date: Tue, 21 May 2019 20:25:52 +0000 Subject: [PATCH] Add test for git-notes --- modules/git/notes.go | 6 ++++- modules/git/notes_test.go | 24 ++++++++++++++++++ modules/git/repo_ref_test.go | 3 ++- .../28/345b214c5967bd9cdd98cc7f88f2f1ac574e02 | Bin 0 -> 85 bytes .../a4/79ead1abb694ffca26f67b09c8313b12fa2a13 | Bin 0 -> 30 bytes .../ca/6b5ddf303169a72d2a2971acde4f6eea194e5c | 4 +++ .../tests/repos/repo1_bare/refs/notes/commits | 1 + 7 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 modules/git/notes_test.go create mode 100644 modules/git/tests/repos/repo1_bare/objects/28/345b214c5967bd9cdd98cc7f88f2f1ac574e02 create mode 100644 modules/git/tests/repos/repo1_bare/objects/a4/79ead1abb694ffca26f67b09c8313b12fa2a13 create mode 100644 modules/git/tests/repos/repo1_bare/objects/ca/6b5ddf303169a72d2a2971acde4f6eea194e5c create mode 100644 modules/git/tests/repos/repo1_bare/refs/notes/commits diff --git a/modules/git/notes.go b/modules/git/notes.go index 574f5adc3e2cb..7aa5d89a79fd9 100644 --- a/modules/git/notes.go +++ b/modules/git/notes.go @@ -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 @@ -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 } diff --git a/modules/git/notes_test.go b/modules/git/notes_test.go new file mode 100644 index 0000000000000..a954377f543d3 --- /dev/null +++ b/modules/git/notes_test.go @@ -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", ¬e) + assert.NoError(t, err) + assert.Equal(t, []byte("Note contents\n"), note.Message) + assert.Equal(t, "Vladimir Panteleev", note.Commit.Author.Name) +} diff --git a/modules/git/repo_ref_test.go b/modules/git/repo_ref_test.go index 2a3ea26a768e8..d32b34994c391 100644 --- a/modules/git/repo_ref_test.go +++ b/modules/git/repo_ref_test.go @@ -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 { diff --git a/modules/git/tests/repos/repo1_bare/objects/28/345b214c5967bd9cdd98cc7f88f2f1ac574e02 b/modules/git/tests/repos/repo1_bare/objects/28/345b214c5967bd9cdd98cc7f88f2f1ac574e02 new file mode 100644 index 0000000000000000000000000000000000000000..05dc4725eaa5c817fd8af3f6c047b4dc9bad3216 GIT binary patch literal 85 zcmV-b0IL6Z0V^p=O;s?nU@$Z=Ff%bxury6dGD$JEG&8YCO*Kz7HZnCdFiS}@FibQv rGE6o#Hn1==PBb$$W>`}B>f-8cQ~sY)`&P|)!q8gimzFR9EFKteb^{)W literal 0 HcmV?d00001 diff --git a/modules/git/tests/repos/repo1_bare/objects/a4/79ead1abb694ffca26f67b09c8313b12fa2a13 b/modules/git/tests/repos/repo1_bare/objects/a4/79ead1abb694ffca26f67b09c8313b12fa2a13 new file mode 100644 index 0000000000000000000000000000000000000000..35d27dcbe7a6557b8143cd5f57ee6851674b3743 GIT binary patch literal 30 mcmb