D2409: graft: add no-commit mode (issue5631)

khanchi97 (Sushil khanchi) phabricator at mercurial-scm.org
Sun Jun 3 10:13:52 EDT 2018


khanchi97 updated this revision to Diff 8961.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2409?vs=8958&id=8961

REVISION DETAIL
  https://phab.mercurial-scm.org/D2409

AFFECTED FILES
  mercurial/commands.py
  tests/test-completion.t
  tests/test-graft.t

CHANGE DETAILS

diff --git a/tests/test-graft.t b/tests/test-graft.t
--- a/tests/test-graft.t
+++ b/tests/test-graft.t
@@ -1536,3 +1536,216 @@
      date:        Thu Jan 01 00:00:00 1970 +0000
      summary:     bar to b
   
+Test for --no-commit option:
+
+  $ cd ..
+  $ hg init nocommit
+  $ cd nocommit
+  $ echo a > a
+  $ hg ci -qAm0
+  $ echo b > b
+  $ hg ci -qAm1
+  $ hg up -q 0
+  $ echo c > c
+  $ hg ci -qAm2
+  $ hg log
+  changeset:   2:db815d6d32e6
+  tag:         tip
+  parent:      0:f7b1eb17ad24
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     2
+  
+  changeset:   1:925d80f479bb
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     1
+  
+  changeset:   0:f7b1eb17ad24
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     0
+  
+
+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:925d80f479bb "1"
+
+  $ hg log
+  changeset:   2:db815d6d32e6
+  tag:         tip
+  parent:      0:f7b1eb17ad24
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     2
+  
+  changeset:   1:925d80f479bb
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     1
+  
+  changeset:   0:f7b1eb17ad24
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     0
+  
+
+  $ 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
+
+Prepare wrdir to check --no-commit is resepected after --continue:
+
+  $ echo A>a
+  $ hg ci -qm4
+  $ hg up -q 1
+  $ echo B>a
+  $ hg ci -qm5
+  $ hg log
+  changeset:   5:b1d5b5056844
+  tag:         tip
+  parent:      1:925d80f479bb
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     5
+  
+  changeset:   4:a08bb3910e7c
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     4
+  
+  changeset:   3:af773ba6509d
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     3
+  
+  changeset:   2:db815d6d32e6
+  parent:      0:f7b1eb17ad24
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     2
+  
+  changeset:   1:925d80f479bb
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     1
+  
+  changeset:   0:f7b1eb17ad24
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     0
+  
+
+  $ 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
+
+Test --no-commit is respected after --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
+
+Prepare wrdir to check --no-commit is resepected when passed with --continue:
+
+  $ 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
+
+Test --no-commit is respected with --continue:
+  $ 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 log
+  changeset:   5:b1d5b5056844
+  tag:         tip
+  parent:      1:925d80f479bb
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     5
+  
+  changeset:   4:a08bb3910e7c
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     4
+  
+  changeset:   3:af773ba6509d
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     3
+  
+  changeset:   2:db815d6d32e6
+  parent:      0:f7b1eb17ad24
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     2
+  
+  changeset:   1:925d80f479bb
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     1
+  
+  changeset:   0:f7b1eb17ad24
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     0
+  
+ 
+  $ cd ..
+
diff --git a/tests/test-completion.t b/tests/test-completion.t
--- a/tests/test-completion.t
+++ b/tests/test-completion.t
@@ -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, edit, log, force, currentdate, currentuser, date, user, tool, dry-run
+  graft: rev, continue, edit, log, force, currentdate, currentuser, date, user, tool, dry-run, no-commit
   grep: print0, all, text, follow, ignore-case, files-with-matches, line-number, rev, user, date, template, include, exclude
   heads: rev, topo, active, closed, style, template
   help: extension, command, keyword, system
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2128,6 +2128,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')),
@@ -2164,7 +2166,7 @@
     .. note::
 
        The -c/--continue option does not reapply earlier options, except
-       for --force, --user and --date.
+       for --force, --user, --date and --no-commit.
 
     .. container:: verbose
 
@@ -2218,6 +2220,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('continue'):
         cont = True
@@ -2230,6 +2246,8 @@
                 opts['date'] = statedata['date']
             if statedata.get('user'):
                 opts['user'] = statedata['user']
+            if statedata.get('no_commit'):
+                opts['no_commit'] = statedata.get('no_commit')
             nodes = statedata['nodes']
             revs = [repo[node].rev() for node in nodes]
         else:
@@ -2316,6 +2334,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,13 +2393,14 @@
         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))
+        # 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))
 
     # remove state when we complete successfully
     if not opts.get('dry_run'):



To: khanchi97, #hg-reviewers, pulkit
Cc: pulkit, mercurial-devel


More information about the Mercurial-devel mailing list