summaryrefslogtreecommitdiff
path: root/reference_test.go
diff options
context:
space:
mode:
authorCarlos Martín Nieto <[email protected]>2015-08-31 19:58:29 +0200
committerCarlos Martín Nieto <[email protected]>2015-08-31 19:58:29 +0200
commit6d3a3499f1639a6272e334f9f74b1e0cf6b0bb49 (patch)
tree04b27dfdf1faadcaff6ca40fa27d8edd690045d1 /reference_test.go
parent157593f38da780c4f6cb6dc61275b9b36a3327bf (diff)
parent4090c401c8bf3f062e898f75bde01e2ef27b3911 (diff)
Merge branch 'master-v23'
Diffstat (limited to 'reference_test.go')
-rw-r--r--reference_test.go73
1 files changed, 54 insertions, 19 deletions
diff --git a/reference_test.go b/reference_test.go
index 5720a66..761daf8 100644
--- a/reference_test.go
+++ b/reference_test.go
@@ -13,21 +13,14 @@ func TestRefModification(t *testing.T) {
commitId, treeId := seedTestRepo(t, repo)
- loc, err := time.LoadLocation("Europe/Berlin")
- checkFatal(t, err)
- sig := &Signature{
- Name: "Rand Om Hacker",
- Email: "[email protected]",
- When: time.Date(2013, 03, 06, 14, 30, 0, 0, loc),
- }
- _, err = repo.CreateReference("refs/tags/tree", treeId, true, sig, "testTreeTag")
+ _, err := repo.References.Create("refs/tags/tree", treeId, true, "testTreeTag")
checkFatal(t, err)
- tag, err := repo.LookupReference("refs/tags/tree")
+ tag, err := repo.References.Lookup("refs/tags/tree")
checkFatal(t, err)
checkRefType(t, tag, ReferenceOid)
- ref, err := repo.LookupReference("HEAD")
+ ref, err := repo.References.Lookup("HEAD")
checkFatal(t, err)
checkRefType(t, ref, ReferenceSymbolic)
@@ -51,9 +44,9 @@ func TestRefModification(t *testing.T) {
t.Fatalf("Wrong ref target")
}
- _, err = tag.Rename("refs/tags/renamed", false, nil, "")
+ _, err = tag.Rename("refs/tags/renamed", false, "")
checkFatal(t, err)
- tag, err = repo.LookupReference("refs/tags/renamed")
+ tag, err = repo.References.Lookup("refs/tags/renamed")
checkFatal(t, err)
checkRefType(t, ref, ReferenceOid)
@@ -84,13 +77,13 @@ func TestReferenceIterator(t *testing.T) {
commitId, err := repo.CreateCommit("HEAD", sig, sig, message, tree)
checkFatal(t, err)
- _, err = repo.CreateReference("refs/heads/one", commitId, true, sig, "headOne")
+ _, err = repo.References.Create("refs/heads/one", commitId, true, "headOne")
checkFatal(t, err)
- _, err = repo.CreateReference("refs/heads/two", commitId, true, sig, "headTwo")
+ _, err = repo.References.Create("refs/heads/two", commitId, true, "headTwo")
checkFatal(t, err)
- _, err = repo.CreateReference("refs/heads/three", commitId, true, sig, "headThree")
+ _, err = repo.References.Create("refs/heads/three", commitId, true, "headThree")
checkFatal(t, err)
iter, err := repo.NewReferenceIterator()
@@ -143,7 +136,7 @@ func TestReferenceOwner(t *testing.T) {
commitId, _ := seedTestRepo(t, repo)
- ref, err := repo.CreateReference("refs/heads/foo", commitId, true, nil, "")
+ ref, err := repo.References.Create("refs/heads/foo", commitId, true, "")
checkFatal(t, err)
owner := ref.Owner()
@@ -162,10 +155,10 @@ func TestUtil(t *testing.T) {
commitId, _ := seedTestRepo(t, repo)
- ref, err := repo.CreateReference("refs/heads/foo", commitId, true, nil, "")
+ ref, err := repo.References.Create("refs/heads/foo", commitId, true, "")
checkFatal(t, err)
- ref2, err := repo.DwimReference("foo")
+ ref2, err := repo.References.Dwim("foo")
checkFatal(t, err)
if ref.Cmp(ref2) != 0 {
@@ -176,13 +169,55 @@ func TestUtil(t *testing.T) {
t.Fatalf("refs/heads/foo has no foo shorthand")
}
- hasLog, err := repo.HasLog("refs/heads/foo")
+ hasLog, err := repo.References.HasLog("refs/heads/foo")
checkFatal(t, err)
if !hasLog {
t.Fatalf("branches have logs by default")
}
}
+func TestIsNote(t *testing.T) {
+ repo := createTestRepo(t)
+ defer cleanupTestRepo(t, repo)
+
+ commitID, _ := seedTestRepo(t, repo)
+
+ sig := &Signature{
+ Name: "Rand Om Hacker",
+ Email: "[email protected]",
+ When: time.Now(),
+ }
+
+ refname, err := repo.Notes.DefaultRef()
+ checkFatal(t, err)
+
+ _, err = repo.Notes.Create(refname, sig, sig, commitID, "This is a note", false)
+ checkFatal(t, err)
+
+ ref, err := repo.References.Lookup(refname)
+ checkFatal(t, err)
+
+ if !ref.IsNote() {
+ t.Fatalf("%s should be a note", ref.Name())
+ }
+
+ ref, err = repo.References.Create("refs/heads/foo", commitID, true, "")
+ checkFatal(t, err)
+
+ if ref.IsNote() {
+ t.Fatalf("%s should not be a note", ref.Name())
+ }
+}
+
+func TestReferenceIsValidName(t *testing.T) {
+ if !ReferenceIsValidName("HEAD") {
+ t.Errorf("HEAD should be a valid reference name")
+ }
+ if ReferenceIsValidName("HEAD1") {
+ t.Errorf("HEAD1 should not be a valid reference name")
+ }
+}
+
func compareStringList(t *testing.T, expected, actual []string) {
for i, v := range expected {
if actual[i] != v {