aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bug/bug.go7
-rw-r--r--cache/repo_cache_bug.go17
-rw-r--r--commands/rm.go22
3 files changed, 28 insertions, 18 deletions
diff --git a/bug/bug.go b/bug/bug.go
index 04bd5996..95c4325f 100644
--- a/bug/bug.go
+++ b/bug/bug.go
@@ -242,11 +242,18 @@ func readBug(repo repository.ClockedRepo, ref string) (*Bug, error) {
return &bug, nil
}
+// 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)
+}
+
type StreamedBug struct {
Bug *Bug
Err error
diff --git a/cache/repo_cache_bug.go b/cache/repo_cache_bug.go
index 0492e7f1..0c26cb38 100644
--- a/cache/repo_cache_bug.go
+++ b/cache/repo_cache_bug.go
@@ -361,13 +361,24 @@ func (c *RepoCache) NewBugRaw(author *IdentityCache, unixTime int64, title strin
}
// RemoveBug removes a bug from the cache and repo
-func (c *RepoCache) RemoveBug(prefix string) error {
- b, err := c.ResolveBugPrefix(prefix)
+// args[0] specifies the bug prefix to remove
+// args[1] (if present) specifies the remote the bug was imported from
+func (c *RepoCache) RemoveBug(args []string) error {
+ if len(args) == 0 {
+ return fmt.Errorf("you must provide a bug prefix to remove")
+ }
+
+ b, err := c.ResolveBugPrefix(args[0])
+
if err != nil {
return err
}
- err = bug.RemoveLocalBug(c.repo, b.Id())
+ if len(args) == 1 {
+ err = bug.RemoveLocalBug(c.repo, b.Id())
+ } else {
+ err = bug.RemoveRemoteBug(c.repo, args[1], b.Id())
+ }
if err != nil {
return err
}
diff --git a/commands/rm.go b/commands/rm.go
index 7b34a629..718fb4a3 100644
--- a/commands/rm.go
+++ b/commands/rm.go
@@ -1,25 +1,20 @@
package commands
import (
- "fmt"
-
"github.com/spf13/cobra"
)
-type rmOptions struct {
-}
-
func newRmCommand() *cobra.Command {
env := newEnv()
- options := rmOptions{}
cmd := &cobra.Command{
- Use: "rm <id>",
+ Use: "rm <id> [<remote>]",
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),
PostRunE: closeBackend(env),
RunE: func(cmd *cobra.Command, args []string) error {
- return runRm(env, options, args)
+ return runRm(env, args)
},
}
@@ -29,17 +24,14 @@ func newRmCommand() *cobra.Command {
return cmd
}
-func runRm(env *Env, opts rmOptions, args []string) error {
- if len(args) == 0 {
- return fmt.Errorf("you must provide a bug id prefix to remove")
- }
+func runRm(env *Env, args []string) (err error) {
+ err = env.backend.RemoveBug(args)
- err := env.backend.RemoveBug(args[0])
if err != nil {
- return err
+ return
}
env.out.Printf("bug %s removed\n", args[0])
- return nil
+ return
}