bug: use NeedCommit() in the interface, drop HasPendingOp()

This commit is contained in:
Michael Muré 2019-11-19 00:28:06 +01:00
parent a9b32e6bda
commit ed2ac793e9
No known key found for this signature in database
GPG Key ID: A4457C029293126F
4 changed files with 18 additions and 9 deletions

View File

@ -160,7 +160,7 @@ func readBug(repo repository.ClockedRepo, ref string) (*Bug, error) {
rootFound = true
}
if strings.HasPrefix(entry.Name, createClockEntryPrefix) {
n, err := fmt.Sscanf(string(entry.Name), createClockEntryPattern, &createTime)
n, err := fmt.Sscanf(entry.Name, createClockEntryPattern, &createTime)
if err != nil {
return nil, errors.Wrap(err, "can't read create lamport time")
}
@ -169,7 +169,7 @@ func readBug(repo repository.ClockedRepo, ref string) (*Bug, error) {
}
}
if strings.HasPrefix(entry.Name, editClockEntryPrefix) {
n, err := fmt.Sscanf(string(entry.Name), editClockEntryPattern, &editTime)
n, err := fmt.Sscanf(entry.Name, editClockEntryPattern, &editTime)
if err != nil {
return nil, errors.Wrap(err, "can't read edit lamport time")
}
@ -350,11 +350,6 @@ func (bug *Bug) Append(op Operation) {
bug.staging.Append(op)
}
// HasPendingOp tell if the bug need to be committed
func (bug *Bug) HasPendingOp() bool {
return !bug.staging.IsEmpty()
}
// Commit write the staging area in Git and move the operations to the packs
func (bug *Bug) Commit(repo repository.ClockedRepo) error {

View File

@ -4,6 +4,7 @@ import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/MichaelMure/git-bug/identity"
@ -18,8 +19,10 @@ func TestPushPull(t *testing.T) {
bug1, _, err := Create(reneA, time.Now().Unix(), "bug1", "message")
require.NoError(t, err)
assert.True(t, bug1.NeedCommit())
err = bug1.Commit(repoA)
require.NoError(t, err)
assert.False(t, bug1.NeedCommit())
// distribute the identity
_, err = identity.Push(repoA, "origin")
@ -91,8 +94,10 @@ func _RebaseTheirs(t testing.TB) {
bug1, _, err := Create(reneA, time.Now().Unix(), "bug1", "message")
require.NoError(t, err)
assert.True(t, bug1.NeedCommit())
err = bug1.Commit(repoA)
require.NoError(t, err)
assert.False(t, bug1.NeedCommit())
// distribute the identity
_, err = identity.Push(repoA, "origin")
@ -111,18 +116,21 @@ func _RebaseTheirs(t testing.TB) {
bug2, err := ReadLocalBug(repoB, bug1.Id())
require.NoError(t, err)
assert.False(t, bug2.NeedCommit())
reneB, err := identity.ReadLocal(repoA, reneA.Id())
require.NoError(t, err)
_, err = AddComment(bug2, reneB, time.Now().Unix(), "message2")
require.NoError(t, err)
assert.True(t, bug2.NeedCommit())
_, err = AddComment(bug2, reneB, time.Now().Unix(), "message3")
require.NoError(t, err)
_, err = AddComment(bug2, reneB, time.Now().Unix(), "message4")
require.NoError(t, err)
err = bug2.Commit(repoB)
require.NoError(t, err)
assert.False(t, bug2.NeedCommit())
// B --> remote
_, err = Push(repoB, "origin")

View File

@ -78,8 +78,11 @@ func TestBugCommitLoad(t *testing.T) {
repo := repository.NewMockRepoForTest()
assert.True(t, bug1.NeedCommit())
err := bug1.Commit(repo)
assert.Nil(t, err)
assert.False(t, bug1.NeedCommit())
bug2, err := ReadLocalBug(repo, bug1.Id())
assert.NoError(t, err)
@ -90,8 +93,11 @@ func TestBugCommitLoad(t *testing.T) {
bug1.Append(setTitleOp)
bug1.Append(addCommentOp)
assert.True(t, bug1.NeedCommit())
err = bug1.Commit(repo)
assert.Nil(t, err)
assert.False(t, bug1.NeedCommit())
bug3, err := ReadLocalBug(repo, bug1.Id())
assert.NoError(t, err)

View File

@ -16,8 +16,8 @@ type Interface interface {
// Append an operation into the staging area, to be committed later
Append(op Operation)
// Append an operation into the staging area, to be committed later
HasPendingOp() bool
// Indicate that the in-memory state changed and need to be commit in the repository
NeedCommit() bool
// Commit write the staging area in Git and move the operations to the packs
Commit(repo repository.ClockedRepo) error