[PATCH] graft: print a message when nothing was grafted (issue3091)

Stefano Tortarolo stefano.tortarolo at gmail.com
Tue Nov 8 14:45:32 CST 2011


# HG changeset patch
# User Stefano Tortarolo <stefano.tortarolo at gmail.com>
# Date 1320785084 -3600
# Node ID cd713156b2bf17cb9085d7bf295e3c8e3b39c75f
# Parent  de7e2fba4326cad80bda0cb100d2ae2f58e67ee8
graft: print a message when nothing was grafted (issue3091)

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2597,8 +2597,10 @@
         date = ctx.date()
         if opts.get('date'):
             date = opts['date']
-        repo.commit(text=ctx.description(), user=user,
+        grafted = repo.commit(text=ctx.description(), user=user,
                     date=date, extra=extra, editor=editor)
+        if not grafted:
+            ui.status(_('nothing to graft\n'))
 
     # remove state when we complete successfully
     if os.path.exists(repo.join('graftstate')):
diff --git a/tests/test-graft-nocommit.t b/tests/test-graft-nocommit.t
new file mode 100644
--- /dev/null
+++ b/tests/test-graft-nocommit.t
@@ -0,0 +1,72 @@
+Create a simple repo
+
+  $ hg init tst
+  $ cd tst
+  $ echo a>a
+  $ hg ci -Am 'A'
+  adding a
+  $ echo b>b
+  $ hg ci -Am 'B'
+  adding b
+  $ echo c>c
+  $ hg ci -Am 'C'
+  adding c
+
+  $ hg up -q 0
+  $ echo d>d
+  $ hg ci -Am 'D'
+  adding d
+  created new head
+  $ echo e>e
+  $ hg ci -Am 'E'
+  adding e
+
+  $ hg --config extensions.graphlog= glog --template '{rev}: {desc}\n'
+  @  4: E
+  |
+  o  3: D
+  |
+  | o  2: C
+  | |
+  | o  1: B
+  |/
+  o  0: A
+  
+Graft works as expected
+
+  $ hg graft 2
+  grafting revision 2
+  $ hg --config extensions.graphlog= glog --template '{rev}: {desc}\n'
+  @  5: C
+  |
+  o  4: E
+  |
+  o  3: D
+  |
+  | o  2: C
+  | |
+  | o  1: B
+  |/
+  o  0: A
+  
+
+Now we try to graft again the same cset
+It doesn't create (correctly) a new cset but the message is misleading
+  $ hg up -q 2
+  $ hg graft 5
+  grafting revision 5
+  nothing to graft
+
+  $ hg --config extensions.graphlog= glog --template '{rev}: {desc}\n'
+  o  5: C
+  |
+  o  4: E
+  |
+  o  3: D
+  |
+  | @  2: C
+  | |
+  | o  1: B
+  |/
+  o  0: A
+  


More information about the Mercurial-devel mailing list