aboutsummaryrefslogtreecommitdiffstats
path: root/bug
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-07-28 14:24:04 +0200
committerMichael Muré <batolettre@gmail.com>2020-07-28 14:30:07 +0200
commita62ce78c4fc4e541cecaab0ab22def8752d3d9e2 (patch)
tree434b75cbe63543ba5f609dadfb0e891765d13ea8 /bug
parent18ddc775905bdeabf2be4afb6fe62d2013b06dec (diff)
downloadgit-bug-a62ce78c4fc4e541cecaab0ab22def8752d3d9e2.tar.gz
bug: code cleanup for the rm feature
Diffstat (limited to 'bug')
-rw-r--r--bug/bug.go28
-rw-r--r--bug/bug_test.go4
2 files changed, 17 insertions, 15 deletions
diff --git a/bug/bug.go b/bug/bug.go
index a47cd9db..2ee89031 100644
--- a/bug/bug.go
+++ b/bug/bug.go
@@ -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)
}