mercurial/commands.py
changeset 19440 4a0d0616c47d
parent 19439 f4148c36f0aa
child 19469 bf6bc4681383
--- a/mercurial/commands.py	Wed Jul 17 23:58:04 2013 +0200
+++ b/mercurial/commands.py	Thu Jul 11 13:11:41 2013 -0400
@@ -1285,6 +1285,7 @@
     ('', 'close-branch', None,
      _('mark a branch as closed, hiding it from the branch list')),
     ('', 'amend', None, _('amend the parent of the working dir')),
+    ('s', 'secret', None, _('use the secret phase for committing')),
     ] + walkopts + commitopts + commitopts2 + subrepoopts,
     _('[OPTION]... [FILE]...'))
 def commit(ui, repo, *pats, **opts):
@@ -1329,6 +1330,9 @@
         # Let --subrepos on the command line override config setting.
         ui.setconfig('ui', 'commitsubrepos', True)
 
+    # Save this for restoring it later
+    oldcommitphase = ui.config('phases', 'new-commit')
+
     if repo.vfs.exists('graftstate'):
         raise util.Abort(_('cannot commit an interrupted graft operation'),
                          hint=_('use "hg graft -c" to continue graft'))
@@ -1370,12 +1374,18 @@
             if not message:
                 message = old.description()
                 editor = cmdutil.commitforceeditor
-            return repo.commit(message,
-                               opts.get('user') or old.user(),
-                               opts.get('date') or old.date(),
-                               match,
-                               editor=editor,
-                               extra=extra)
+            try:
+                if opts.get('secret'):
+                    ui.setconfig('phases', 'new-commit', 'secret')
+
+                return repo.commit(message,
+                                   opts.get('user') or old.user(),
+                                   opts.get('date') or old.date(),
+                                   match,
+                                   editor=editor,
+                                   extra=extra)
+            finally:
+                ui.setconfig('phases', 'new-commit', oldcommitphase)
 
         current = repo._bookmarkcurrent
         marks = old.bookmarks()
@@ -1398,8 +1408,15 @@
             e = cmdutil.commitforceeditor
 
         def commitfunc(ui, repo, message, match, opts):
-            return repo.commit(message, opts.get('user'), opts.get('date'),
-                               match, editor=e, extra=extra)
+            try:
+                if opts.get('secret'):
+                    ui.setconfig('phases', 'new-commit', 'secret')
+
+                return repo.commit(message, opts.get('user'), opts.get('date'),
+                                   match, editor=e, extra=extra)
+            finally:
+                ui.setconfig('phases', 'new-commit', oldcommitphase)
+
 
         node = cmdutil.commit(ui, repo, commitfunc, pats, opts)