Mercurial > public > mercurial-scm > hg
comparison mercurial/commands.py @ 38473:622f79e3a1cb
graft: add no-commit mode (issue5631)
This patch adds a new flag --no-commit in graft command. This feature
grafts the changes but do not create commits for those changes, grafted
changes will be added in the working directory. Also added tests to reflect
the expected behavior.
Differential Revision: https://phab.mercurial-scm.org/D2409
author | Sushil khanchi <sushilkhanchi97@gmail.com> |
---|---|
date | Tue, 26 Jun 2018 16:14:02 +0530 |
parents | 854c2ccc800e |
children | 8d9d0d30cfcc |
comparison
equal
deleted
inserted
replaced
38472:d17d1ee1d602 | 38473:622f79e3a1cb |
---|---|
2109 ('c', 'continue', False, _('resume interrupted graft')), | 2109 ('c', 'continue', False, _('resume interrupted graft')), |
2110 ('', 'stop', False, _('stop interrupted graft')), | 2110 ('', 'stop', False, _('stop interrupted graft')), |
2111 ('', 'abort', False, _('abort interrupted graft')), | 2111 ('', 'abort', False, _('abort interrupted graft')), |
2112 ('e', 'edit', False, _('invoke editor on commit messages')), | 2112 ('e', 'edit', False, _('invoke editor on commit messages')), |
2113 ('', 'log', None, _('append graft info to log message')), | 2113 ('', 'log', None, _('append graft info to log message')), |
2114 ('', 'no-commit', None, | |
2115 _("don't commit, just apply the changes in working directory")), | |
2114 ('f', 'force', False, _('force graft')), | 2116 ('f', 'force', False, _('force graft')), |
2115 ('D', 'currentdate', False, | 2117 ('D', 'currentdate', False, |
2116 _('record the current date as commit date')), | 2118 _('record the current date as commit date')), |
2117 ('U', 'currentuser', False, | 2119 ('U', 'currentuser', False, |
2118 _('record the current user as committer'), _('DATE'))] | 2120 _('record the current user as committer'), _('DATE'))] |
2198 | 2200 |
2199 editor = cmdutil.getcommiteditor(editform='graft', | 2201 editor = cmdutil.getcommiteditor(editform='graft', |
2200 **pycompat.strkwargs(opts)) | 2202 **pycompat.strkwargs(opts)) |
2201 | 2203 |
2202 cont = False | 2204 cont = False |
2205 if opts.get('no_commit'): | |
2206 if opts.get('edit'): | |
2207 raise error.Abort(_("cannot specify --no-commit and " | |
2208 "--edit together")) | |
2209 if opts.get('currentuser'): | |
2210 raise error.Abort(_("cannot specify --no-commit and " | |
2211 "--currentuser together")) | |
2212 if opts.get('currentdate'): | |
2213 raise error.Abort(_("cannot specify --no-commit and " | |
2214 "--currentdate together")) | |
2215 if opts.get('log'): | |
2216 raise error.Abort(_("cannot specify --no-commit and " | |
2217 "--log together")) | |
2218 | |
2203 graftstate = statemod.cmdstate(repo, 'graftstate') | 2219 graftstate = statemod.cmdstate(repo, 'graftstate') |
2204 | 2220 |
2205 if opts.get('stop'): | 2221 if opts.get('stop'): |
2206 if opts.get('continue'): | 2222 if opts.get('continue'): |
2207 raise error.Abort(_("cannot use '--continue' and " | 2223 raise error.Abort(_("cannot use '--continue' and " |
2235 opts['date'] = statedata['date'] | 2251 opts['date'] = statedata['date'] |
2236 if statedata.get('user'): | 2252 if statedata.get('user'): |
2237 opts['user'] = statedata['user'] | 2253 opts['user'] = statedata['user'] |
2238 if statedata.get('log'): | 2254 if statedata.get('log'): |
2239 opts['log'] = True | 2255 opts['log'] = True |
2256 if statedata.get('no_commit'): | |
2257 opts['no_commit'] = statedata.get('no_commit') | |
2240 nodes = statedata['nodes'] | 2258 nodes = statedata['nodes'] |
2241 revs = [repo[node].rev() for node in nodes] | 2259 revs = [repo[node].rev() for node in nodes] |
2242 else: | 2260 else: |
2243 cmdutil.wrongtooltocontinue(repo, _('graft')) | 2261 cmdutil.wrongtooltocontinue(repo, _('graft')) |
2244 else: | 2262 else: |
2321 (r, repo[r], rev, ctx)) | 2339 (r, repo[r], rev, ctx)) |
2322 revs.remove(r) | 2340 revs.remove(r) |
2323 if not revs: | 2341 if not revs: |
2324 return -1 | 2342 return -1 |
2325 | 2343 |
2344 if opts.get('no_commit'): | |
2345 statedata['no_commit'] = True | |
2326 for pos, ctx in enumerate(repo.set("%ld", revs)): | 2346 for pos, ctx in enumerate(repo.set("%ld", revs)): |
2327 desc = '%d:%s "%s"' % (ctx.rev(), ctx, | 2347 desc = '%d:%s "%s"' % (ctx.rev(), ctx, |
2328 ctx.description().split('\n', 1)[0]) | 2348 ctx.description().split('\n', 1)[0]) |
2329 names = repo.nodetags(ctx.node()) + repo.nodebookmarks(ctx.node()) | 2349 names = repo.nodetags(ctx.node()) + repo.nodebookmarks(ctx.node()) |
2330 if names: | 2350 if names: |
2371 _("unresolved conflicts, can't continue"), | 2391 _("unresolved conflicts, can't continue"), |
2372 hint=hint) | 2392 hint=hint) |
2373 else: | 2393 else: |
2374 cont = False | 2394 cont = False |
2375 | 2395 |
2376 # commit | 2396 # commit if --no-commit is false |
2377 node = repo.commit(text=message, user=user, | 2397 if not opts.get('no_commit'): |
2378 date=date, extra=extra, editor=editor) | 2398 node = repo.commit(text=message, user=user, date=date, extra=extra, |
2379 if node is None: | 2399 editor=editor) |
2380 ui.warn( | 2400 if node is None: |
2381 _('note: graft of %d:%s created no changes to commit\n') % | 2401 ui.warn( |
2382 (ctx.rev(), ctx)) | 2402 _('note: graft of %d:%s created no changes to commit\n') % |
2383 # checking that newnodes exist because old state files won't have it | 2403 (ctx.rev(), ctx)) |
2384 elif statedata.get('newnodes') is not None: | 2404 # checking that newnodes exist because old state files won't have it |
2385 statedata['newnodes'].append(node) | 2405 elif statedata.get('newnodes') is not None: |
2406 statedata['newnodes'].append(node) | |
2386 | 2407 |
2387 # remove state when we complete successfully | 2408 # remove state when we complete successfully |
2388 if not opts.get('dry_run'): | 2409 if not opts.get('dry_run'): |
2389 graftstate.delete() | 2410 graftstate.delete() |
2390 | 2411 |