diff --git a/bug/bug.go b/bug/bug.go index 95c4325fb929e3c3d948036c00896aab6b169980..148e49bf83864d97c1aaae2f09de89e9397e8bf9 100644 --- a/bug/bug.go +++ b/bug/bug.go @@ -243,15 +243,18 @@ func readBug(repo repository.ClockedRepo, ref string) (*Bug, error) { } // RemoveLocalBug will remove a local bug from its hash -func RemoveLocalBug(repo repository.ClockedRepo, id entity.Id) error { - ref := bugsRefPattern + id.String() - return repo.RemoveRef(ref) -} - -// RemoveRemoteBug will remove a remote bug locally from its hash -func RemoveRemoteBug(repo repository.ClockedRepo, remote string, id entity.Id) error { - ref := fmt.Sprintf(bugsRemoteRefPattern, remote) + id.String() - return repo.RemoveRef(ref) +func RemoveBug(repo repository.ClockedRepo, id entity.Id) error { + refs, err := repo.ListRefs(id.String()) + if err != nil { + return err + } + for _, ref := range refs { + err = repo.RemoveRef(ref) + if err != nil { + return err + } + } + return nil } type StreamedBug struct { diff --git a/cache/repo_cache_bug.go b/cache/repo_cache_bug.go index c7e2ed34a74aa0eb995d885ef53523c9ba3c2549..34e2a14426b81e1c4c409378b09442ab89a4a10a 100644 --- a/cache/repo_cache_bug.go +++ b/cache/repo_cache_bug.go @@ -361,23 +361,14 @@ func (c *RepoCache) NewBugRaw(author *IdentityCache, unixTime int64, title strin } // RemoveBug removes a bug from the cache and repo -// args[0] specifies the bug prefix to remove -// args[1] (if present) specifies the remote the bug was imported from -func (c *RepoCache) RemoveBug(prefix string, remote string) error { +func (c *RepoCache) RemoveBug(prefix string) error { b, err := c.ResolveBugPrefix(prefix) if err != nil { return err } - if remote == "" { - err = bug.RemoveLocalBug(c.repo, b.Id()) - } else { - err = bug.RemoveRemoteBug(c.repo, remote, b.Id()) - } - if err != nil { - return err - } + err = bug.RemoveBug(c.repo, b.Id()) delete(c.bugs, b.Id()) delete(c.bugExcerpts, b.Id()) diff --git a/commands/rm.go b/commands/rm.go index 800f16e13899e86fe737286a38e310cfff58c357..90a79539bef554ce72e5fddf4b54baabbbb20cf0 100644 --- a/commands/rm.go +++ b/commands/rm.go @@ -10,7 +10,7 @@ func newRmCommand() *cobra.Command { env := newEnv() cmd := &cobra.Command{ - Use: "rm []", + Use: "rm ", Short: "Remove an existing bug.", Long: "Remove an existing bug in the local repository. If the bug was imported from a bridge, specify the remote name to remove it from. Note removing bugs that were imported from bridges will not remove the bug remote, and will only remove the local copy of the bug.", PreRunE: loadBackendEnsureUser(env), @@ -27,16 +27,12 @@ func newRmCommand() *cobra.Command { } func runRm(env *Env, args []string) (err error) { - switch len(args) { - case 1: - err = env.backend.RemoveBug(args[0], "") - break - case 2: - err = env.backend.RemoveBug(args[0], args[1]) - default: - return errors.New("invalid number of arguments for rm command") + if len(args) == 0 { + return errors.New("you must provide a bug prefix to remove") } + err = env.backend.RemoveBug(args[0]) + if err != nil { return }