diff options
-rw-r--r-- | bug/bug.go | 28 | ||||
-rw-r--r-- | bug/bug_test.go | 4 | ||||
-rw-r--r-- | cache/repo_cache_test.go | 5 |
3 files changed, 22 insertions, 15 deletions
@@ -244,17 +244,18 @@ func readBug(repo repository.ClockedRepo, ref string) (*Bug, error) { // RemoveBug will remove a local bug from its entity.Id func RemoveBug(repo repository.ClockedRepo, id entity.Id) error { - matching := entity.Id("") - fullMatches := []string{} + var fullMatches []string refs, err := repo.ListRefs(bugsRefPattern + id.String()) if err != nil { return err - } else if num := len(refs); num > 1 { + } + if len(refs) > 1 { return NewErrMultipleMatchBug(refsToIds(refs)) - } else if num == 1 { - matching = refToId(refs[0]) - fullMatches = []string{refs[0]} + } + if len(refs) == 1 { + // we have the bug locally + fullMatches = append(fullMatches, refs[0]) } remotes, err := repo.GetRemotes() @@ -267,20 +268,17 @@ func RemoveBug(repo repository.ClockedRepo, id entity.Id) error { remoteRefs, err := repo.ListRefs(remotePrefix) if err != nil { return err - } else if num := len(remoteRefs); num > 1 { + } + if len(remoteRefs) > 1 { return NewErrMultipleMatchBug(refsToIds(refs)) - } else if num == 1 { - id := refToId(remoteRefs[0]) + } + if len(remoteRefs) == 1 { + // found the bug in a remote fullMatches = append(fullMatches, remoteRefs[0]) - if matching.String() == "" { - matching = id - } else if id != matching { - return NewErrMultipleMatchBug([]entity.Id{matching, id}) - } } } - if matching == "" { + if len(fullMatches) == 0 { return ErrBugNotExist } diff --git a/bug/bug_test.go b/bug/bug_test.go index d6c80efc..400e50f8 100644 --- a/bug/bug_test.go +++ b/bug/bug_test.go @@ -171,4 +171,8 @@ func TestBugRemove(t *testing.T) { _, err = ReadRemoteBug(repo, "remoteB", b.Id()) require.Error(t, ErrBugNotExist, err) + + ids, err := ListLocalIds(repo) + require.NoError(t, err) + require.Len(t, ids, 100) } diff --git a/cache/repo_cache_test.go b/cache/repo_cache_test.go index e5603fca..0deb155e 100644 --- a/cache/repo_cache_test.go +++ b/cache/repo_cache_test.go @@ -8,6 +8,7 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "github.com/MichaelMure/git-bug/bug" "github.com/MichaelMure/git-bug/query" "github.com/MichaelMure/git-bug/repository" ) @@ -204,4 +205,8 @@ func TestRemove(t *testing.T) { err = repoCache.RemoveBug(b1.Id().String()) require.NoError(t, err) assert.Equal(t, 100, len(repoCache.bugs)) + assert.Equal(t, 100, len(repoCache.bugExcerpts)) + + _, err = repoCache.ResolveBug(b1.Id()) + assert.Error(t, bug.ErrBugNotExist, err) } |