Patchwork [5,of,5,topic-experiment] topics: abort if user wants to show the stack of a non-existent topic

login
register
mail settings
Submitter Pulkit Goyal
Date June 18, 2017, 10:12 p.m.
Message ID <8d8ac3adc1f9e03625d2.1497823944@workspace>
Download mbox | patch
Permalink /patch/21494/
State Accepted
Headers show

Comments

Pulkit Goyal - June 18, 2017, 10:12 p.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1497822215 -19800
#      Mon Jun 19 03:13:35 2017 +0530
# Node ID 8d8ac3adc1f9e03625d293ae78f250b115154d94
# Parent  83df91589000c05359805c96fa84a3995896ee3c
topics: abort if user wants to show the stack of a non-existent topic
Pierre-Yves David - June 19, 2017, 6:31 a.m.
I've taken the whole series Thanks!

There is still multiple unsolved issue around issue5441, but patch2 make 
things move forward so I've taken it. See comment on this specific patch 
for details.

On 06/19/2017 12:12 AM, Pulkit Goyal wrote:
> # HG changeset patch
> # User Pulkit Goyal <7895pulkit@gmail.com>
> # Date 1497822215 -19800
> #      Mon Jun 19 03:13:35 2017 +0530
> # Node ID 8d8ac3adc1f9e03625d293ae78f250b115154d94
> # Parent  83df91589000c05359805c96fa84a3995896ee3c
> topics: abort if user wants to show the stack of a non-existent topic
>
> diff --git a/hgext3rd/topic/stack.py b/hgext3rd/topic/stack.py
> --- a/hgext3rd/topic/stack.py
> +++ b/hgext3rd/topic/stack.py
> @@ -22,6 +22,10 @@
>      return ' '.join(prefix % suffix for suffix in labelssuffix)
>
>  def showstack(ui, repo, topic, opts):
> +
> +    if topic not in repo.topics:
> +        raise error.Abort(_('cannot resolve "%s": no such topic found') % topic)
> +
>      fm = ui.formatter('topicstack', opts)
>      prev = None
>      entries = []
> diff --git a/tests/test-topic-stack.t b/tests/test-topic-stack.t
> --- a/tests/test-topic-stack.t
> +++ b/tests/test-topic-stack.t
> @@ -319,3 +319,11 @@
>    t2@ c_D (current)
>    t1: c_c
>      ^ c_b
> +
> +Trying to list non existing topic
> +  $ hg stack thisdoesnotexist
> +  abort: cannot resolve "thisdoesnotexist": no such topic found
> +  [255]
> +  $ hg topic --list thisdoesnotexist
> +  abort: cannot resolve "thisdoesnotexist": no such topic found
> +  [255]
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@mercurial-scm.org
> https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
>

Patch

diff --git a/hgext3rd/topic/stack.py b/hgext3rd/topic/stack.py
--- a/hgext3rd/topic/stack.py
+++ b/hgext3rd/topic/stack.py
@@ -22,6 +22,10 @@ 
     return ' '.join(prefix % suffix for suffix in labelssuffix)
 
 def showstack(ui, repo, topic, opts):
+
+    if topic not in repo.topics:
+        raise error.Abort(_('cannot resolve "%s": no such topic found') % topic)
+
     fm = ui.formatter('topicstack', opts)
     prev = None
     entries = []
diff --git a/tests/test-topic-stack.t b/tests/test-topic-stack.t
--- a/tests/test-topic-stack.t
+++ b/tests/test-topic-stack.t
@@ -319,3 +319,11 @@ 
   t2@ c_D (current)
   t1: c_c
     ^ c_b
+
+Trying to list non existing topic
+  $ hg stack thisdoesnotexist
+  abort: cannot resolve "thisdoesnotexist": no such topic found
+  [255]
+  $ hg topic --list thisdoesnotexist
+  abort: cannot resolve "thisdoesnotexist": no such topic found
+  [255]