Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commands.py @ 19440:4a0d0616c47d
commit: enable --secret option
At the moment, creating secret commits is slightly cumbersome. They
can either be created by changing the default commit phase to secret
or by doing `hg phase --secret --force`. Both of these make secret
commits appear to be like some kind of advanced feature.
Secret commits, however, should be a convenient feature for people who
want to work on a private branch without affecting anyone else. There
should therefore be a prominent and convenient method for creating
secret commits.
Since the default phase is draft and there is no need to use --force
to go from a secret phase to any other phase, this patch
intentionally does not add --draft and --public options.
author | Jordi Guti?rrez Hermoso <jordigh@octave.org> |
---|---|
date | Thu, 11 Jul 2013 13:11:41 -0400 |
parents | f4148c36f0aa |
children | bf6bc4681383 |
comparison
equal
deleted
inserted
replaced
19439:f4148c36f0aa | 19440:4a0d0616c47d |
---|---|
1283 [('A', 'addremove', None, | 1283 [('A', 'addremove', None, |
1284 _('mark new/missing files as added/removed before committing')), | 1284 _('mark new/missing files as added/removed before committing')), |
1285 ('', 'close-branch', None, | 1285 ('', 'close-branch', None, |
1286 _('mark a branch as closed, hiding it from the branch list')), | 1286 _('mark a branch as closed, hiding it from the branch list')), |
1287 ('', 'amend', None, _('amend the parent of the working dir')), | 1287 ('', 'amend', None, _('amend the parent of the working dir')), |
1288 ('s', 'secret', None, _('use the secret phase for committing')), | |
1288 ] + walkopts + commitopts + commitopts2 + subrepoopts, | 1289 ] + walkopts + commitopts + commitopts2 + subrepoopts, |
1289 _('[OPTION]... [FILE]...')) | 1290 _('[OPTION]... [FILE]...')) |
1290 def commit(ui, repo, *pats, **opts): | 1291 def commit(ui, repo, *pats, **opts): |
1291 """commit the specified files or all outstanding changes | 1292 """commit the specified files or all outstanding changes |
1292 | 1293 |
1327 if opts.get('amend'): | 1328 if opts.get('amend'): |
1328 raise util.Abort(_('cannot amend with --subrepos')) | 1329 raise util.Abort(_('cannot amend with --subrepos')) |
1329 # Let --subrepos on the command line override config setting. | 1330 # Let --subrepos on the command line override config setting. |
1330 ui.setconfig('ui', 'commitsubrepos', True) | 1331 ui.setconfig('ui', 'commitsubrepos', True) |
1331 | 1332 |
1333 # Save this for restoring it later | |
1334 oldcommitphase = ui.config('phases', 'new-commit') | |
1335 | |
1332 if repo.vfs.exists('graftstate'): | 1336 if repo.vfs.exists('graftstate'): |
1333 raise util.Abort(_('cannot commit an interrupted graft operation'), | 1337 raise util.Abort(_('cannot commit an interrupted graft operation'), |
1334 hint=_('use "hg graft -c" to continue graft')) | 1338 hint=_('use "hg graft -c" to continue graft')) |
1335 | 1339 |
1336 branch = repo[None].branch() | 1340 branch = repo[None].branch() |
1368 # message contains text from -m or -l, if it's empty, | 1372 # message contains text from -m or -l, if it's empty, |
1369 # open the editor with the old message | 1373 # open the editor with the old message |
1370 if not message: | 1374 if not message: |
1371 message = old.description() | 1375 message = old.description() |
1372 editor = cmdutil.commitforceeditor | 1376 editor = cmdutil.commitforceeditor |
1373 return repo.commit(message, | 1377 try: |
1374 opts.get('user') or old.user(), | 1378 if opts.get('secret'): |
1375 opts.get('date') or old.date(), | 1379 ui.setconfig('phases', 'new-commit', 'secret') |
1376 match, | 1380 |
1377 editor=editor, | 1381 return repo.commit(message, |
1378 extra=extra) | 1382 opts.get('user') or old.user(), |
1383 opts.get('date') or old.date(), | |
1384 match, | |
1385 editor=editor, | |
1386 extra=extra) | |
1387 finally: | |
1388 ui.setconfig('phases', 'new-commit', oldcommitphase) | |
1379 | 1389 |
1380 current = repo._bookmarkcurrent | 1390 current = repo._bookmarkcurrent |
1381 marks = old.bookmarks() | 1391 marks = old.bookmarks() |
1382 node = cmdutil.amend(ui, repo, commitfunc, old, extra, pats, opts) | 1392 node = cmdutil.amend(ui, repo, commitfunc, old, extra, pats, opts) |
1383 if node == old.node(): | 1393 if node == old.node(): |
1396 e = cmdutil.commiteditor | 1406 e = cmdutil.commiteditor |
1397 if opts.get('force_editor'): | 1407 if opts.get('force_editor'): |
1398 e = cmdutil.commitforceeditor | 1408 e = cmdutil.commitforceeditor |
1399 | 1409 |
1400 def commitfunc(ui, repo, message, match, opts): | 1410 def commitfunc(ui, repo, message, match, opts): |
1401 return repo.commit(message, opts.get('user'), opts.get('date'), | 1411 try: |
1402 match, editor=e, extra=extra) | 1412 if opts.get('secret'): |
1413 ui.setconfig('phases', 'new-commit', 'secret') | |
1414 | |
1415 return repo.commit(message, opts.get('user'), opts.get('date'), | |
1416 match, editor=e, extra=extra) | |
1417 finally: | |
1418 ui.setconfig('phases', 'new-commit', oldcommitphase) | |
1419 | |
1403 | 1420 |
1404 node = cmdutil.commit(ui, repo, commitfunc, pats, opts) | 1421 node = cmdutil.commit(ui, repo, commitfunc, pats, opts) |
1405 | 1422 |
1406 if not node: | 1423 if not node: |
1407 stat = repo.status(match=scmutil.match(repo[None], pats, opts)) | 1424 stat = repo.status(match=scmutil.match(repo[None], pats, opts)) |