aboutsummaryrefslogtreecommitdiffstats
path: root/bug
diff options
context:
space:
mode:
Diffstat (limited to 'bug')
-rw-r--r--bug/bug.go4
-rw-r--r--bug/bug_test.go36
2 files changed, 24 insertions, 16 deletions
diff --git a/bug/bug.go b/bug/bug.go
index 1717dd66..f84753fa 100644
--- a/bug/bug.go
+++ b/bug/bug.go
@@ -459,6 +459,7 @@ func (bug *Bug) Commit(repo repository.ClockedRepo) error {
return err
}
+ bug.staging.commitHash = hash
bug.packs = append(bug.packs, bug.staging)
bug.staging = OperationPack{}
@@ -513,9 +514,8 @@ func (bug *Bug) Merge(repo repository.Repo, other Interface) (bool, error) {
}
ancestor, err := repo.FindCommonAncestor(bug.lastCommit, otherBug.lastCommit)
-
if err != nil {
- return false, err
+ return false, errors.Wrap(err, "can't find common ancestor")
}
ancestorIndex := 0
diff --git a/bug/bug_test.go b/bug/bug_test.go
index 41a5b03d..001bfc56 100644
--- a/bug/bug_test.go
+++ b/bug/bug_test.go
@@ -55,7 +55,7 @@ func TestBugValidity(t *testing.T) {
}
}
-func TestBugSerialisation(t *testing.T) {
+func TestBugCommitLoad(t *testing.T) {
bug1 := NewBug()
bug1.Append(createOp)
@@ -69,22 +69,30 @@ func TestBugSerialisation(t *testing.T) {
assert.Nil(t, err)
bug2, err := ReadLocalBug(repo, bug1.Id())
- if err != nil {
- t.Error(err)
- }
+ assert.NoError(t, err)
+ equivalentBug(t, bug1, bug2)
- // ignore some fields
- bug2.packs[0].commitHash = bug1.packs[0].commitHash
- for i := range bug1.packs[0].Operations {
- bug2.packs[0].Operations[i].base().hash = bug1.packs[0].Operations[i].base().hash
- }
+ // add more op
+
+ bug1.Append(setTitleOp)
+ bug1.Append(addCommentOp)
+
+ err = bug1.Commit(repo)
+ assert.Nil(t, err)
+
+ bug3, err := ReadLocalBug(repo, bug1.Id())
+ assert.NoError(t, err)
+ equivalentBug(t, bug1, bug3)
+}
+
+func equivalentBug(t *testing.T, expected, actual *Bug) {
+ assert.Equal(t, len(expected.packs), len(actual.packs))
- // check hashes
- for i := range bug1.packs[0].Operations {
- if !bug2.packs[0].Operations[i].base().hash.IsValid() {
- t.Fatal("invalid hash")
+ for i := range expected.packs {
+ for j := range expected.packs[i].Operations {
+ actual.packs[i].Operations[j].base().hash = expected.packs[i].Operations[j].base().hash
}
}
- assert.Equal(t, bug1, bug2)
+ assert.Equal(t, expected, actual)
}