topic: add a --topic option to "push" command
authorDenis Laxalde <denis.laxalde@logilab.fr>
Fri, 22 Sep 2017 13:43:38 +0200
changeset 2982 fef934b7ed86
parent 2981 86be70ae38b9
child 2983 c0de0010ec30
topic: add a --topic option to "push" command This is symmetrical with --bookmark or --branch; it selects changesets in specified topic as revisions to push.
README
hgext3rd/topic/__init__.py
tests/test-topic-push.t
--- a/README	Fri Sep 22 12:48:57 2017 +0200
+++ b/README	Fri Sep 22 13:43:38 2017 +0200
@@ -137,6 +137,7 @@
   * topic: add a new 'debugconvertbookmark' commands.
     It helps migrating from bookmark feature branch to topic feature branch.
   * topic: small clarification and cleanup on various output
+  * push: add a --topic option to mirror --bookmark and --branch.
 
 6.6.0 -- 2017-07-25
 -------------------
--- a/hgext3rd/topic/__init__.py	Fri Sep 22 12:48:57 2017 +0200
+++ b/hgext3rd/topic/__init__.py	Fri Sep 22 13:43:38 2017 +0200
@@ -198,6 +198,10 @@
     entry[1].append(('t', 'topic', '',
                      _("use specified topic"), _('TOPIC')))
 
+    entry = extensions.wrapcommand(commands.table, 'push', pushwrap)
+    entry[1].append(('t', 'topic', '',
+                     _("topic to push"), _('TOPIC')))
+
     extensions.wrapfunction(cmdutil, 'buildcommittext', committextwrap)
     extensions.wrapfunction(merge, 'update', mergeupdatewrap)
     # We need to check whether t0 or b0 is passed to override the default update
@@ -824,6 +828,12 @@
                           "\nHG: topic '%s'\nHG: branch" % t)
     return ret
 
+def pushwrap(orig, ui, repo, *args, **opts):
+    if opts.get('topic'):
+        topicrevs = repo.revs('topic(%s) - obsolete()', opts['topic'])
+        opts.setdefault('rev', []).extend(topicrevs)
+    return orig(ui, repo, *args, **opts)
+
 def mergeupdatewrap(orig, repo, node, branchmerge, force, *args, **kwargs):
     matcher = kwargs.get('matcher')
     partial = not (matcher is None or matcher.always())
--- a/tests/test-topic-push.t	Fri Sep 22 12:48:57 2017 +0200
+++ b/tests/test-topic-push.t	Fri Sep 22 13:43:38 2017 +0200
@@ -157,6 +157,57 @@
   |/
   o  0 default  public CA
   
+push --topic
+
+  $ hg log -G -R $TESTTMP/draft
+  o  3 default babar draft CD
+  |
+  | o  2 mountain  public CC
+  |/
+  | o  1 default  public CB
+  |/
+  o  0 default  public CA
+  
+  $ echo bbb >> aaa
+  $ hg commit -m "C'A"
+  $ hg up 1
+  2 files updated, 0 files merged, 1 files removed, 0 files unresolved
+  $ hg topic --clear
+  $ echo bbb >> bbb
+  $ hg commit -m "C'B"
+  $ hg log -G
+  @  6 default  draft C'B
+  |
+  | o  5 default babar draft C'A
+  | |
+  | o  4 default babar draft CD
+  | |
+  | | o  3 mountain  public CC
+  | |/
+  o |  1 default  public CB
+  |/
+  o  0 default  public CA
+  
+  $ hg push draft --topic babar
+  pushing to $TESTTMP/draft
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+  $ hg log -G -R $TESTTMP/draft
+  o  4 default babar draft C'A
+  |
+  o  3 default babar draft CD
+  |
+  | o  2 mountain  public CC
+  |/
+  | o  1 default  public CB
+  |/
+  o  0 default  public CA
+  
+  $ hg strip --config extensions.strip= --no-backup -r 5: --quiet
+  $ hg strip --config extensions.strip= -R $TESTTMP/draft --no-backup -r 4: --quiet
 
 Pushing a new topic to a publishing server should be seen as a new head