Mercurial > public > mercurial-scm > hg
comparison contrib/phabricator.py @ 33690:40cfe3197bc1
phabricator: add --confirm option to phabsend command
This adds a --confirm flag similar to the confirm flag of `hg email` using which
one can confirm the changesets before they get emailed. The confirm flag will
show the changesets and ask for confirmation before sending them.
Differential Revision: https://phab.mercurial-scm.org/D218
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Thu, 03 Aug 2017 03:09:33 +0530 |
parents | 850d2ec2cf6a |
children | 1664406a44d9 |
comparison
equal
deleted
inserted
replaced
33689:9c27a2891b75 | 33690:40cfe3197bc1 |
---|---|
311 % ' '.join(sorted(unresolved))) | 311 % ' '.join(sorted(unresolved))) |
312 return [entry[r'phid'] for entry in data] | 312 return [entry[r'phid'] for entry in data] |
313 | 313 |
314 @command('phabsend', | 314 @command('phabsend', |
315 [('r', 'rev', [], _('revisions to send'), _('REV')), | 315 [('r', 'rev', [], _('revisions to send'), _('REV')), |
316 ('', 'reviewer', [], _('specify reviewers'))], | 316 ('', 'reviewer', [], _('specify reviewers')), |
317 ('', 'confirm', None, _('ask for confirmation before sending'))], | |
317 _('REV [OPTIONS]')) | 318 _('REV [OPTIONS]')) |
318 def phabsend(ui, repo, *revs, **opts): | 319 def phabsend(ui, repo, *revs, **opts): |
319 """upload changesets to Phabricator | 320 """upload changesets to Phabricator |
320 | 321 |
321 If there are multiple revisions specified, they will be send as a stack | 322 If there are multiple revisions specified, they will be send as a stack |
324 | 325 |
325 For the first time uploading changesets, local tags will be created to | 326 For the first time uploading changesets, local tags will be created to |
326 maintain the association. After the first time, phabsend will check | 327 maintain the association. After the first time, phabsend will check |
327 obsstore and tags information so it can figure out whether to update an | 328 obsstore and tags information so it can figure out whether to update an |
328 existing Differential Revision, or create a new one. | 329 existing Differential Revision, or create a new one. |
330 | |
331 The --confirm option lets you confirm changesets before sending them. You | |
332 can also add following to your configuration file to make it default | |
333 behaviour. | |
334 | |
335 [phabsend] | |
336 confirm = true | |
329 """ | 337 """ |
330 revs = list(revs) + opts.get('rev', []) | 338 revs = list(revs) + opts.get('rev', []) |
331 revs = scmutil.revrange(repo, revs) | 339 revs = scmutil.revrange(repo, revs) |
332 | 340 |
333 if not revs: | 341 if not revs: |
334 raise error.Abort(_('phabsend requires at least one changeset')) | 342 raise error.Abort(_('phabsend requires at least one changeset')) |
343 | |
344 confirm = ui.configbool('phabsend', 'confirm') | |
345 confirm |= bool(opts.get('confirm')) | |
346 if confirm: | |
347 confirmed = _confirmbeforesend(repo, revs) | |
348 if not confirmed: | |
349 raise error.Abort(_('phabsend cancelled')) | |
335 | 350 |
336 actions = [] | 351 actions = [] |
337 reviewers = opts.get('reviewer', []) | 352 reviewers = opts.get('reviewer', []) |
338 if reviewers: | 353 if reviewers: |
339 phids = userphids(repo, reviewers) | 354 phids = userphids(repo, reviewers) |
376 | 391 |
377 # Map from "hg:meta" keys to header understood by "hg import". The order is | 392 # Map from "hg:meta" keys to header understood by "hg import". The order is |
378 # consistent with "hg export" output. | 393 # consistent with "hg export" output. |
379 _metanamemap = util.sortdict([(r'user', 'User'), (r'date', 'Date'), | 394 _metanamemap = util.sortdict([(r'user', 'User'), (r'date', 'Date'), |
380 (r'node', 'Node ID'), (r'parent', 'Parent ')]) | 395 (r'node', 'Node ID'), (r'parent', 'Parent ')]) |
396 | |
397 def _confirmbeforesend(repo, revs): | |
398 ui = repo.ui | |
399 for rev in revs: | |
400 ctx = repo[rev] | |
401 desc = ctx.description().splitlines()[0] | |
402 ui.write(('%d: ' % rev), label='phabsend.revnumber') | |
403 ui.write(('%s\n' % desc), label='phabsend.desc') | |
404 | |
405 if ui.promptchoice(_('Phabsend the above changes (yn)?' | |
406 '$$ &Yes $$ &No')): | |
407 return False | |
408 | |
409 return True | |
381 | 410 |
382 def querydrev(repo, params, stack=False): | 411 def querydrev(repo, params, stack=False): |
383 """return a list of "Differential Revision" dicts | 412 """return a list of "Differential Revision" dicts |
384 | 413 |
385 params is the input of "differential.query" API, and is expected to match | 414 params is the input of "differential.query" API, and is expected to match |