# HG changeset patch # User Sushil khanchi # Date 1530009842 -19800 # Node ID 622f79e3a1cb310191825722894a725219e78c3c # Parent d17d1ee1d60235741922a0ce9a680e0f13f31821 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 diff -r d17d1ee1d602 -r 622f79e3a1cb mercurial/commands.py --- a/mercurial/commands.py Tue Jun 26 02:05:11 2018 +0530 +++ b/mercurial/commands.py Tue Jun 26 16:14:02 2018 +0530 @@ -2111,6 +2111,8 @@ ('', 'abort', False, _('abort interrupted graft')), ('e', 'edit', False, _('invoke editor on commit messages')), ('', 'log', None, _('append graft info to log message')), + ('', 'no-commit', None, + _("don't commit, just apply the changes in working directory")), ('f', 'force', False, _('force graft')), ('D', 'currentdate', False, _('record the current date as commit date')), @@ -2200,6 +2202,20 @@ **pycompat.strkwargs(opts)) cont = False + if opts.get('no_commit'): + if opts.get('edit'): + raise error.Abort(_("cannot specify --no-commit and " + "--edit together")) + if opts.get('currentuser'): + raise error.Abort(_("cannot specify --no-commit and " + "--currentuser together")) + if opts.get('currentdate'): + raise error.Abort(_("cannot specify --no-commit and " + "--currentdate together")) + if opts.get('log'): + raise error.Abort(_("cannot specify --no-commit and " + "--log together")) + graftstate = statemod.cmdstate(repo, 'graftstate') if opts.get('stop'): @@ -2237,6 +2253,8 @@ opts['user'] = statedata['user'] if statedata.get('log'): opts['log'] = True + if statedata.get('no_commit'): + opts['no_commit'] = statedata.get('no_commit') nodes = statedata['nodes'] revs = [repo[node].rev() for node in nodes] else: @@ -2323,6 +2341,8 @@ if not revs: return -1 + if opts.get('no_commit'): + statedata['no_commit'] = True for pos, ctx in enumerate(repo.set("%ld", revs)): desc = '%d:%s "%s"' % (ctx.rev(), ctx, ctx.description().split('\n', 1)[0]) @@ -2373,16 +2393,17 @@ else: cont = False - # commit - node = repo.commit(text=message, user=user, - date=date, extra=extra, editor=editor) - if node is None: - ui.warn( - _('note: graft of %d:%s created no changes to commit\n') % - (ctx.rev(), ctx)) - # checking that newnodes exist because old state files won't have it - elif statedata.get('newnodes') is not None: - statedata['newnodes'].append(node) + # commit if --no-commit is false + if not opts.get('no_commit'): + node = repo.commit(text=message, user=user, date=date, extra=extra, + editor=editor) + if node is None: + ui.warn( + _('note: graft of %d:%s created no changes to commit\n') % + (ctx.rev(), ctx)) + # checking that newnodes exist because old state files won't have it + elif statedata.get('newnodes') is not None: + statedata['newnodes'].append(node) # remove state when we complete successfully if not opts.get('dry_run'): diff -r d17d1ee1d602 -r 622f79e3a1cb tests/test-completion.t --- a/tests/test-completion.t Tue Jun 26 02:05:11 2018 +0530 +++ b/tests/test-completion.t Tue Jun 26 16:14:02 2018 +0530 @@ -312,7 +312,7 @@ debugwireargs: three, four, five, ssh, remotecmd, insecure debugwireproto: localssh, peer, noreadstderr, nologhandshake, ssh, remotecmd, insecure files: rev, print0, include, exclude, template, subrepos - graft: rev, continue, stop, abort, edit, log, force, currentdate, currentuser, date, user, tool, dry-run + graft: rev, continue, stop, abort, edit, log, no-commit, force, currentdate, currentuser, date, user, tool, dry-run grep: print0, all, diff, text, follow, ignore-case, files-with-matches, line-number, rev, allfiles, user, date, template, include, exclude heads: rev, topo, active, closed, style, template help: extension, command, keyword, system diff -r d17d1ee1d602 -r 622f79e3a1cb tests/test-graft.t --- a/tests/test-graft.t Tue Jun 26 02:05:11 2018 +0530 +++ b/tests/test-graft.t Tue Jun 26 16:14:02 2018 +0530 @@ -1885,3 +1885,246 @@ new changesets detected on destination branch, can't strip graft aborted working directory is now at 6b98ff0062dd + + $ cd .. + +============================ +Testing --no-commit option:| +============================ + + $ hg init nocommit + $ cd nocommit + $ echo a > a + $ hg ci -qAma + $ echo b > b + $ hg ci -qAmb + $ hg up -q 0 + $ echo c > c + $ hg ci -qAmc + $ hg log -GT "{rev}:{node|short} {desc}\n" + @ 2:d36c0562f908 c + | + | o 1:d2ae7f538514 b + |/ + o 0:cb9a9f314b8b a + + +Check reporting when --no-commit used with non-applicable options: + + $ hg graft 1 --no-commit -e + abort: cannot specify --no-commit and --edit together + [255] + + $ hg graft 1 --no-commit --log + abort: cannot specify --no-commit and --log together + [255] + + $ hg graft 1 --no-commit -D + abort: cannot specify --no-commit and --currentdate together + [255] + +Test --no-commit is working: + $ hg graft 1 --no-commit + grafting 1:d2ae7f538514 "b" + + $ hg log -GT "{rev}:{node|short} {desc}\n" + @ 2:d36c0562f908 c + | + | o 1:d2ae7f538514 b + |/ + o 0:cb9a9f314b8b a + + + $ hg diff + diff -r d36c0562f908 b + --- /dev/null Thu Jan 01 00:00:00 1970 +0000 + +++ b/b Thu Jan 01 00:00:00 1970 +0000 + @@ -0,0 +1,1 @@ + +b + +Prepare wrdir to check --no-commit is resepected after --continue: + + $ hg up -qC + $ echo A>a + $ hg ci -qm "A in file a" + $ hg up -q 1 + $ echo B>a + $ hg ci -qm "B in file a" + $ hg log -GT "{rev}:{node|short} {desc}\n" + @ 4:2aa9ad1006ff B in file a + | + | o 3:09e253b87e17 A in file a + | | + | o 2:d36c0562f908 c + | | + o | 1:d2ae7f538514 b + |/ + o 0:cb9a9f314b8b a + + + $ hg graft 3 --no-commit + grafting 3:09e253b87e17 "A in file a" + merging a + warning: conflicts while merging a! (edit, then use 'hg resolve --mark') + abort: unresolved conflicts, can't continue + (use 'hg resolve' and 'hg graft --continue') + [255] + +Resolve conflict: + $ echo A>a + $ hg resolve --mark + (no more unresolved files) + continue: hg graft --continue + + $ hg graft --continue + grafting 3:09e253b87e17 "A in file a" + $ hg log -GT "{rev}:{node|short} {desc}\n" + @ 4:2aa9ad1006ff B in file a + | + | o 3:09e253b87e17 A in file a + | | + | o 2:d36c0562f908 c + | | + o | 1:d2ae7f538514 b + |/ + o 0:cb9a9f314b8b a + + $ hg diff + diff -r 2aa9ad1006ff a + --- a/a Thu Jan 01 00:00:00 1970 +0000 + +++ b/a Thu Jan 01 00:00:00 1970 +0000 + @@ -1,1 +1,1 @@ + -B + +A + + $ hg up -qC + +Check --no-commit is resepected when passed with --continue: + + $ hg graft 3 + grafting 3:09e253b87e17 "A in file a" + merging a + warning: conflicts while merging a! (edit, then use 'hg resolve --mark') + abort: unresolved conflicts, can't continue + (use 'hg resolve' and 'hg graft --continue') + [255] + +Resolve conflict: + $ echo A>a + $ hg resolve --mark + (no more unresolved files) + continue: hg graft --continue + + $ hg graft --continue --no-commit + grafting 3:09e253b87e17 "A in file a" + $ hg diff + diff -r 2aa9ad1006ff a + --- a/a Thu Jan 01 00:00:00 1970 +0000 + +++ b/a Thu Jan 01 00:00:00 1970 +0000 + @@ -1,1 +1,1 @@ + -B + +A + + $ hg log -GT "{rev}:{node|short} {desc}\n" + @ 4:2aa9ad1006ff B in file a + | + | o 3:09e253b87e17 A in file a + | | + | o 2:d36c0562f908 c + | | + o | 1:d2ae7f538514 b + |/ + o 0:cb9a9f314b8b a + + $ hg up -qC + +Test --no-commit when graft multiple revisions: +When there is conflict: + $ hg graft -r "2::3" --no-commit + grafting 2:d36c0562f908 "c" + grafting 3:09e253b87e17 "A in file a" + merging a + warning: conflicts while merging a! (edit, then use 'hg resolve --mark') + abort: unresolved conflicts, can't continue + (use 'hg resolve' and 'hg graft --continue') + [255] + + $ echo A>a + $ hg resolve --mark + (no more unresolved files) + continue: hg graft --continue + $ hg graft --continue + grafting 3:09e253b87e17 "A in file a" + $ hg diff + diff -r 2aa9ad1006ff a + --- a/a Thu Jan 01 00:00:00 1970 +0000 + +++ b/a Thu Jan 01 00:00:00 1970 +0000 + @@ -1,1 +1,1 @@ + -B + +A + diff -r 2aa9ad1006ff c + --- /dev/null Thu Jan 01 00:00:00 1970 +0000 + +++ b/c Thu Jan 01 00:00:00 1970 +0000 + @@ -0,0 +1,1 @@ + +c + + $ hg log -GT "{rev}:{node|short} {desc}\n" + @ 4:2aa9ad1006ff B in file a + | + | o 3:09e253b87e17 A in file a + | | + | o 2:d36c0562f908 c + | | + o | 1:d2ae7f538514 b + |/ + o 0:cb9a9f314b8b a + + $ hg up -qC + +When there is no conflict: + $ echo d>d + $ hg add d -q + $ hg ci -qmd + $ hg up 3 -q + $ hg log -GT "{rev}:{node|short} {desc}\n" + o 5:baefa8927fc0 d + | + o 4:2aa9ad1006ff B in file a + | + | @ 3:09e253b87e17 A in file a + | | + | o 2:d36c0562f908 c + | | + o | 1:d2ae7f538514 b + |/ + o 0:cb9a9f314b8b a + + + $ hg graft -r 1 -r 5 --no-commit + grafting 1:d2ae7f538514 "b" + grafting 5:baefa8927fc0 "d" (tip) + $ hg diff + diff -r 09e253b87e17 b + --- /dev/null Thu Jan 01 00:00:00 1970 +0000 + +++ b/b Thu Jan 01 00:00:00 1970 +0000 + @@ -0,0 +1,1 @@ + +b + diff -r 09e253b87e17 d + --- /dev/null Thu Jan 01 00:00:00 1970 +0000 + +++ b/d Thu Jan 01 00:00:00 1970 +0000 + @@ -0,0 +1,1 @@ + +d + $ hg log -GT "{rev}:{node|short} {desc}\n" + o 5:baefa8927fc0 d + | + o 4:2aa9ad1006ff B in file a + | + | @ 3:09e253b87e17 A in file a + | | + | o 2:d36c0562f908 c + | | + o | 1:d2ae7f538514 b + |/ + o 0:cb9a9f314b8b a + + $ cd ..