[PATCH] import: add a --secret option

Denis Laxalde denis at laxalde.org
Thu Nov 21 09:40:07 UTC 2019


# HG changeset patch
# User Denis Laxalde <denis.laxalde at logilab.fr>
# Date 1574324750 -3600
#      Thu Nov 21 09:25:50 2019 +0100
# Node ID f847210f92b94a13d7e260611e41d5508aeacb99
# Parent  039fbd14d4e2889be830cc114957c31972c6ea04
import: add a --secret option

Similarly to "hg commit", we add a --secret option to "hg import" for
committing with the secret phase. The option has no short form since
there already is a "-s" for "--similarity".

.. feature::

   ``hg import`` has a new --secret option for committing with the
    secret phase.

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1773,6 +1773,8 @@ def tryimportone(ui, repo, patchdata, pa
             overrides = {}
             if partial:
                 overrides[(b'ui', b'allowemptycommit')] = True
+            if opts.get(b'secret'):
+                overrides[(b'phases', b'new-commit')] = b'secret'
             with repo.ui.configoverride(overrides, b'import'):
                 n = repo.commit(
                     message, user, date, match=m, editor=editor, extra=extra
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -4033,6 +4033,7 @@ def identify(
             _(b'NUM'),
         ),
         (b'b', b'base', b'', _(b'base path (DEPRECATED)'), _(b'PATH')),
+        (b'', b'secret', None, _(b'use the secret phase for committing')),
         (b'e', b'edit', False, _(b'invoke editor on commit messages')),
         (
             b'f',
@@ -4181,6 +4182,8 @@ def import_(ui, repo, patch1=None, *patc
     update = not opts.get(b'bypass')
     if not update and opts.get(b'no_commit'):
         raise error.Abort(_(b'cannot use --no-commit with --bypass'))
+    if opts.get(b'secret') and opts.get(b'no_commit'):
+        raise error.Abort(_(b'cannot use --no-commit with --secret'))
     try:
         sim = float(opts.get(b'similarity') or 0)
     except ValueError:
diff --git a/tests/test-import.t b/tests/test-import.t
--- a/tests/test-import.t
+++ b/tests/test-import.t
@@ -435,6 +435,49 @@ hg email --plain, should read X-Mercuria
   date:        Thu Jan 01 00:00:00 1970 +0000
   summary:     second change
   
+  $ hg --cwd b phase tip
+  1: draft
+  $ rm -r b
+
+
+hg import --secret
+
+  $ hg clone -r0 a b -q
+  $ hg --cwd b import --no-commit --secret ../exported-tip.patch
+  abort: cannot use --no-commit with --secret
+  [255]
+  $ hg --cwd b import --secret ../exported-tip.patch
+  applying ../exported-tip.patch
+  $ hg --cwd b diff -c . --nodates
+  diff -r 80971e65b431 -r 1d4bd90af0e4 a
+  --- a/a
+  +++ b/a
+  @@ -1,1 +1,2 @@
+   line 1
+  +line 2
+  $ hg --cwd b phase
+  1: secret
+  $ hg --cwd b --config extensions.strip= strip 1 --no-backup --quiet
+  $ HGEDITOR=cat hg --cwd b import --secret --edit ../exported-tip.patch
+  applying ../exported-tip.patch
+  second change
+  
+  
+  HG: Enter commit message.  Lines beginning with 'HG:' are removed.
+  HG: Leave message empty to abort commit.
+  HG: --
+  HG: user: someone
+  HG: branch 'default'
+  HG: changed a
+  $ hg --cwd b diff -c . --nodates
+  diff -r 80971e65b431 -r 1d4bd90af0e4 a
+  --- a/a
+  +++ b/a
+  @@ -1,1 +1,2 @@
+   line 1
+  +line 2
+  $ hg --cwd b phase
+  1: secret
   $ rm -r b
 
 


More information about the Mercurial-devel mailing list