diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -2074,6 +2074,8 @@ ('c', 'continue', False, _('resume 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')), @@ -2110,7 +2112,7 @@ .. note:: The -c/--continue option does not reapply earlier options, except - for --force. + for --force and --no-commit. .. container:: verbose @@ -2162,13 +2164,31 @@ **pycompat.strkwargs(opts)) cont = False + if opts.get('no_commit'): + if opts.get('edit'): + raise error.Abort(_("can't specify --no-commit and --edit")) + elif opts.get('currentdate'): + raise error.Abort(_("can't specify --no-commit and --currentdate")) + elif opts.get('currentuser'): + raise error.Abort(_("can't specify --no-commit and --currentuser")) + elif opts.get('date'): + raise error.Abort(_("can't specify --no-commit and --date")) + elif opts.get('user'): + raise error.Abort(_("can't specify --no-commit and --user")) + if opts.get('continue'): + if opts.get('no_commit'): + lines = repo.vfs.read('graftstate').splitlines(True) + nodelines = [line for line in lines[1:]] + repo.vfs.write('graftstate', 'True\n') + repo.vfs.append('graftstate', ''.join(nodelines)) cont = True if revs: raise error.Abort(_("can't specify --continue and revisions")) # read in unfinished revisions try: - nodes = repo.vfs.read('graftstate').splitlines() + lines = repo.vfs.read('graftstate').splitlines() + nodes = lines[1:] revs = [repo[node].rev() for node in nodes] except IOError as inst: if inst.errno != errno.ENOENT: @@ -2297,8 +2317,15 @@ # report any conflicts if stats and stats[3] > 0: # write out state for --continue + if opts.get('no_commit') and pos == 0: + repo.vfs.write('graftstate', 'True\n') + elif repo.vfs.exists('graftstate'): + lines = repo.vfs.read('graftstate').splitlines() + repo.vfs.write('graftstate', lines[0] + '\n') + else: + repo.vfs.write('graftstate', 'False\n') nodelines = [repo[rev].hex() + "\n" for rev in revs[pos:]] - repo.vfs.write('graftstate', ''.join(nodelines)) + repo.vfs.append('graftstate', ''.join(nodelines)) extra = '' if opts.get('user'): extra += ' --user %s' % util.shellquote(opts['user']) @@ -2314,12 +2341,17 @@ 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)) + nocommitflag = 'False' + if opts.get('continue'): + lines = repo.vfs.read('graftstate').splitlines() + nocommitflag = lines[0] + if not (opts.get('no_commit') or nocommitflag == 'True'): + 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)) # remove state when we complete successfully if not opts.get('dry_run'): diff --git a/tests/test-graft.t b/tests/test-graft.t --- a/tests/test-graft.t +++ b/tests/test-graft.t @@ -1373,3 +1373,104 @@ note: graft of 7:d3c3f2b38ecc created no changes to commit $ cd .. + +Graft a change from a branch without making any commit using --no-commit option: + + $ hg init dirtochecknocommit + $ cd dirtochecknocommit + $ echo a > a + $ hg ci -qAm0 + $ echo b > b + $ hg ci -qAm1 + $ hg up -q 0 + $ echo c > c + $ hg ci -qAm2 +Check --no-commit do not work with those options which are used for making a commit +like -e/-D/-U/-d/-u: + $ hg graft 1 --no-commit -e + abort: can't specify --no-commit and --edit + [255] + $ hg graft 1 --no-commit + grafting 1:925d80f479bb "1" + + $ hg tip -T "rev: {rev}\n" + rev: 2 + + $ hg diff + diff -r db815d6d32e6 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 + + $ hg ci -qm3 + +Make a conflict between two heads and check --no-commit is resepected after --continue: + + $ echo A>a + $ hg ci -qm4 + $ hg up -q 1 + $ echo B>a + $ hg ci -qm5 + $ hg graft 4 --no-commit + grafting 4:a08bb3910e7c "4" + 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] + +Resolving conflict: + + $ echo A>a + $ hg resolve --mark + (no more unresolved files) + continue: hg graft --continue + +Continue: + + $ hg graft --continue + grafting 4:a08bb3910e7c "4" + + $ hg tip -T "rev: {rev}\n" + rev: 5 + + $ hg diff + diff -r b1d5b5056844 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 + +For checking --continue and --no-commit, again make the same conflict: + $ echo B>a + $ hg graft 4 + grafting 4:a08bb3910e7c "4" + 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] + +Resolving conflict: + + $ echo A>a + $ hg resolve --mark + (no more unresolved files) + continue: hg graft --continue + +Continue with --no-commit: + $ hg graft --continue --no-commit + grafting 4:a08bb3910e7c "4" + $ hg diff + diff -r b1d5b5056844 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 tip -T "rev: {rev}\n" + rev: 5 + + $ cd ..