split: add a --interactive flag
authorBoris Feld <boris.feld@octobus.net>
Thu, 13 Dec 2018 17:40:41 +0000
changeset 4300 702f7e1d0b01
parent 4299 4af0235e7b0b
child 4301 5cbaf5d25443
split: add a --interactive flag While the interactive mode is useful for end-users, there are some cases where they don't need the interactivity overhead. Moreover, this allow the split command to be used in automated scripts.
CHANGELOG
hgext3rd/evolve/cmdrewrite.py
tests/test-split.t
--- a/CHANGELOG	Wed Feb 21 14:39:48 2018 +0100
+++ b/CHANGELOG	Thu Dec 13 17:40:41 2018 +0000
@@ -8,6 +8,7 @@
   * split: make it possible to drop change during a split
   * split: no longer accept revision with --rev (BC)
   * split: accept file patterns
+  * split: support for non interactive splits
   * push: have `--publish` overrule the `auto-publish` config
   * next: evolve aspiring children by default (use --no-evolve to skip)
   * next: pick lower part of a split as destination
--- a/hgext3rd/evolve/cmdrewrite.py	Wed Feb 21 14:39:48 2018 +0100
+++ b/hgext3rd/evolve/cmdrewrite.py	Thu Dec 13 17:40:41 2018 +0000
@@ -1132,7 +1132,8 @@
 
 @eh.command(
     'split',
-    [('r', 'rev', [], _("revision to split"), _('REV')),
+    [('i', 'interactive', True, _('use interactive mode')),
+     ('r', 'rev', [], _("revision to split"), _('REV')),
      ('n', 'note', '', _("store a note on split"), _('TEXT')),
     ] + commitopts + commitopts2 + commitopts3,
     _('hg split [OPTION] [-r REV] [FILES]'),
@@ -1153,6 +1154,7 @@
     _resolveoptions(ui, opts)
     tr = wlock = lock = None
     newcommits = []
+    iselect = opts.pop('interactive')
 
     revs = opts.get('rev') or '.'
     if not revs:
@@ -1212,11 +1214,19 @@
         while haschanges():
 
             if haschanges(matcher):
-                cmdutil.dorecord(ui, repo, commands.commit, 'commit', False,
-                                 cmdutil.recordfilter, *pats, **opts)
-                # TODO: Does no seem like the best way to do this
-                # We should make dorecord return the newly created commit
-                newcommits.append(repo['.'])
+                if iselect:
+                    cmdutil.dorecord(ui, repo, commands.commit, 'commit', False,
+                                     cmdutil.recordfilter, *pats, **opts)
+                    # TODO: Does no seem like the best way to do this
+                    # We should make dorecord return the newly created commit
+                    newcommits.append(repo['.'])
+                elif not pats:
+                    msg = _("no files of directories specified")
+                    hint = _("do you want --interactive")
+                    raise error.Abort(msg, hint=hint)
+                else:
+                    commands.commit(ui, repo, *pats, **opts)
+                    newcommits.append(repo['.'])
             if pats:
                 # refresh the wctx used for the matcher
                 matcher = scmutil.match(repo[None], pats)
--- a/tests/test-split.t	Wed Feb 21 14:39:48 2018 +0100
+++ b/tests/test-split.t	Thu Dec 13 17:40:41 2018 +0000
@@ -897,3 +897,79 @@
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   $ hg add SPLIT3
   $ hg amend
+
+Non interractive run
+--------------------
+
+No patterns
+
+  $ hg split --no-interactive
+  0 files updated, 0 files merged, 3 files removed, 0 files unresolved
+  adding SPLIT2
+  adding SPLIT3
+  adding SPLIT4
+  abort: no files of directories specified
+  (do you want --interactive)
+  [255]
+
+Selecting unrelated file
+(should we abort?)
+
+  $ hg split --no-interactive SPLIT1
+  0 files updated, 0 files merged, 3 files removed, 0 files unresolved
+  adding SPLIT2
+  adding SPLIT3
+  adding SPLIT4
+  no more change to split
+  $ hg status --change '.'
+  A SPLIT2
+  A SPLIT3
+  A SPLIT4
+
+Selecting one file
+
+  $ hg split --no-interactive SPLIT2
+  0 files updated, 0 files merged, 3 files removed, 0 files unresolved
+  adding SPLIT2
+  adding SPLIT3
+  adding SPLIT4
+  no more change to split
+  $ hg status --change '.~1'
+  A SPLIT2
+  $ hg status --change '.'
+  A SPLIT3
+  A SPLIT4
+  $ hg fold --from '.~1'
+  2 changesets folded
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+Selecting two files
+
+  $ hg split --no-interactive SPLIT2 SPLIT3
+  0 files updated, 0 files merged, 3 files removed, 0 files unresolved
+  adding SPLIT2
+  adding SPLIT3
+  adding SPLIT4
+  no more change to split
+  $ hg status --change '.~1'
+  A SPLIT2
+  A SPLIT3
+  $ hg status --change '.'
+  A SPLIT4
+  $ hg fold --from '.~1'
+  2 changesets folded
+  0 files updated, 0 files merged, 0 files removed, 0 files unresolved
+
+Selecting all files
+(should we abort?)
+
+  $ hg split --no-interactive .
+  0 files updated, 0 files merged, 3 files removed, 0 files unresolved
+  adding SPLIT2
+  adding SPLIT3
+  adding SPLIT4
+  no more change to split
+  $ hg status --change '.'
+  A SPLIT2
+  A SPLIT3
+  A SPLIT4