commit: add --draft option to use draft phase
authorMartin von Zweigbergk <martinvonz@google.com>
Tue, 29 Nov 2022 13:07:16 -0800
changeset 49882 f0e9dda408b3
parent 49881 9da992241302
child 49883 e78a41686464
commit: add --draft option to use draft phase
mercurial/commands.py
tests/test-alias.t
tests/test-completion.t
tests/test-phases.t
tests/test-qrecord.t
tests/test-record.t
--- a/mercurial/commands.py	Tue Nov 29 14:40:17 2022 -0800
+++ b/mercurial/commands.py	Tue Nov 29 13:07:16 2022 -0800
@@ -2008,6 +2008,7 @@
         (b'', b'close-branch', None, _(b'mark a branch head as closed')),
         (b'', b'amend', None, _(b'amend the parent of the working directory')),
         (b's', b'secret', None, _(b'use the secret phase for committing')),
+        (b'', b'draft', None, _(b'use the draft phase for committing')),
         (b'e', b'edit', None, _(b'invoke editor on commit messages')),
         (
             b'',
@@ -2082,6 +2083,7 @@
 
           hg commit --amend --date now
     """
+    cmdutil.check_at_most_one_arg(opts, 'draft', 'secret')
     cmdutil.check_incompatible_arguments(opts, 'subrepos', ['amend'])
     with repo.wlock(), repo.lock():
         return _docommit(ui, repo, *pats, **opts)
@@ -2174,6 +2176,8 @@
             overrides = {}
             if opts.get(b'secret'):
                 overrides[(b'phases', b'new-commit')] = b'secret'
+            elif opts.get(b'draft'):
+                overrides[(b'phases', b'new-commit')] = b'draft'
 
             baseui = repo.baseui
             with baseui.configoverride(overrides, b'commit'):
--- a/tests/test-alias.t	Tue Nov 29 14:40:17 2022 -0800
+++ b/tests/test-alias.t	Tue Nov 29 13:07:16 2022 -0800
@@ -119,6 +119,7 @@
       --close-branch        mark a branch head as closed
       --amend               amend the parent of the working directory
    -s --secret              use the secret phase for committing
+      --draft               use the draft phase for committing
    -e --edit                invoke editor on commit messages
    -i --interactive         use interactive mode
    -I --include PATTERN [+] include names matching the given patterns
--- a/tests/test-completion.t	Tue Nov 29 14:40:17 2022 -0800
+++ b/tests/test-completion.t	Tue Nov 29 13:07:16 2022 -0800
@@ -264,7 +264,7 @@
   bundle: exact, force, rev, branch, base, all, type, ssh, remotecmd, insecure
   cat: output, rev, decode, include, exclude, template
   clone: noupdate, updaterev, rev, branch, pull, uncompressed, stream, ssh, remotecmd, insecure
-  commit: addremove, close-branch, amend, secret, edit, force-close-branch, interactive, include, exclude, message, logfile, date, user, subrepos
+  commit: addremove, close-branch, amend, secret, draft, edit, force-close-branch, interactive, include, exclude, message, logfile, date, user, subrepos
   config: untrusted, exp-all-known, edit, local, source, shared, non-shared, global, template
   continue: dry-run
   copy: forget, after, at-rev, force, include, exclude, dry-run
--- a/tests/test-phases.t	Tue Nov 29 14:40:17 2022 -0800
+++ b/tests/test-phases.t	Tue Nov 29 13:07:16 2022 -0800
@@ -1117,3 +1117,30 @@
   $ hg up tip
   2 files updated, 0 files merged, 1 files removed, 0 files unresolved
   $ cd ..
+
+Testing that command line flags override configuration
+
+  $ hg init commit-overrides
+  $ cd commit-overrides
+
+`hg commit --draft` overrides new-commit=secret
+
+  $ mkcommit A --config phases.new-commit='secret' --draft
+  test-debug-phase: new rev 0:  x -> 1
+  test-hook-close-phase: 4a2df7238c3b48766b5e22fafbb8a2f506ec8256:   -> draft
+  $ hglog
+  @  0 1 A
+  
+
+`hg commit --secret` overrides new-commit=draft
+
+  $ mkcommit B --config phases.new-commit='draft' --secret
+  test-debug-phase: new rev 1:  x -> 2
+  test-hook-close-phase: 27547f69f25460a52fff66ad004e58da7ad3fb56:   -> secret
+  $ hglog
+  @  1 2 B
+  |
+  o  0 1 A
+  
+
+  $ cd ..
--- a/tests/test-qrecord.t	Tue Nov 29 14:40:17 2022 -0800
+++ b/tests/test-qrecord.t	Tue Nov 29 13:07:16 2022 -0800
@@ -68,6 +68,7 @@
       --close-branch        mark a branch head as closed
       --amend               amend the parent of the working directory
    -s --secret              use the secret phase for committing
+      --draft               use the draft phase for committing
    -e --edit                invoke editor on commit messages
    -I --include PATTERN [+] include names matching the given patterns
    -X --exclude PATTERN [+] exclude names matching the given patterns
--- a/tests/test-record.t	Tue Nov 29 14:40:17 2022 -0800
+++ b/tests/test-record.t	Tue Nov 29 13:07:16 2022 -0800
@@ -51,6 +51,7 @@
       --close-branch        mark a branch head as closed
       --amend               amend the parent of the working directory
    -s --secret              use the secret phase for committing
+      --draft               use the draft phase for committing
    -e --edit                invoke editor on commit messages
    -I --include PATTERN [+] include names matching the given patterns
    -X --exclude PATTERN [+] exclude names matching the given patterns