hgext3rd/topic/__init__.py
changeset 2984 30f6030dca8f
parent 2983 c0de0010ec30
child 2985 f63c97c01f92
--- a/hgext3rd/topic/__init__.py	Fri Sep 22 13:46:41 2017 +0200
+++ b/hgext3rd/topic/__init__.py	Tue Sep 26 12:27:43 2017 +0200
@@ -438,6 +438,11 @@
         return
 
     if clear:
+        ct = repo.currenttopic
+        empty = stack.stackdata(repo, topic=ct)['changesetcount'] == 0
+        if empty:
+            if ct:
+                ui.status(_('clearing empty topic "%s"\n') % ct)
         return _changecurrenttopic(repo, None)
 
     if topic:
@@ -852,12 +857,13 @@
         # if rebase is running and update the currenttopic to topic of new
         # rebased commit. We have explicitly stored in config if rebase is
         # running.
+        ot = repo.currenttopic
+        empty = stack.stackdata(repo, topic=ot)['changesetcount'] == 0
         if repo.ui.hasconfig('experimental', 'topicrebase'):
             isrebase = True
         if repo.ui.configbool('_internal', 'keep-topic'):
             ist0 = True
         if ((not partial and not branchmerge) or isrebase) and not ist0:
-            ot = repo.currenttopic
             t = ''
             pctx = repo[node]
             if pctx.phase() > phases.public:
@@ -866,9 +872,10 @@
                 f.write(t)
             if t and t != ot:
                 repo.ui.status(_("switching to topic %s\n") % t)
+            if ot and not t and empty:
+                repo.ui.status(_('clearing empty topic "%s"\n') % ot)
         elif ist0:
-            repo.ui.status(_("preserving the current topic '%s'\n") %
-                           repo.currenttopic)
+            repo.ui.status(_("preserving the current topic '%s'\n") % ot)
         return ret
     finally:
         wlock.release()