aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-09-26 16:50:10 +0200
committerMichael Muré <batolettre@gmail.com>2018-09-26 16:50:10 +0200
commit66f3b37c945c2a8703fc8874ddaa42d771e906d3 (patch)
treeb0c698308f11f2de5222f5ed1e8f1384318e7574
parent86792d789298269fcdacc2bba193bd5b922b48b7 (diff)
downloadgit-bug-66f3b37c945c2a8703fc8874ddaa42d771e906d3.tar.gz
select: clear the selected bug when invalid
-rw-r--r--commands/select/select.go17
1 files changed, 16 insertions, 1 deletions
diff --git a/commands/select/select.go b/commands/select/select.go
index 203a2f1e..522cc295 100644
--- a/commands/select/select.go
+++ b/commands/select/select.go
@@ -27,6 +27,7 @@ var ErrNoValidId = errors.New("you must provide a bug id")
// has been used
// - an error if the process failed
func ResolveBug(repo *cache.RepoCache, args []string) (*cache.BugCache, []string, error) {
+ // At first, try to use the first argument as a bug prefix
if len(args) > 0 {
b, err := repo.ResolveBugPrefix(args[0])
@@ -39,17 +40,31 @@ func ResolveBug(repo *cache.RepoCache, args []string) (*cache.BugCache, []string
}
}
- // first arg is not a valid bug prefix
+ // first arg is not a valid bug prefix, we can safely use the preselected bug if any
b, err := selected(repo)
+
+ // selected bug is invalid
+ if err == bug.ErrBugNotExist {
+ // we clear the selected bug
+ err = Clear(repo)
+ if err != nil {
+ return nil, nil, err
+ }
+ return nil, nil, ErrNoValidId
+ }
+
+ // another error when reading the bug
if err != nil {
return nil, nil, err
}
+ // bug is successfully retrieved
if b != nil {
return b, args, nil
}
+ // no selected bug and no valid first argument
return nil, nil, ErrNoValidId
}