changeset 29214:ceca932c080d

histedit: add experimental config for using the first word of the commit This allows users to start a commit with "verb! ..." so that when this is opened in histedit, the default action will be "verb". For example, "roll! foo" will default to the action "roll". Currently, we'll allow any known verb to be used but this is experimental.
author Sean Farley <sean@farley.io>
date Fri, 06 May 2016 18:12:36 -0700
parents 4a3d55281a85
children f5983805574e
files hgext/histedit.py tests/test-histedit-arguments.t
diffstat 2 files changed, 58 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/histedit.py	Fri May 06 18:00:03 2016 -0700
+++ b/hgext/histedit.py	Fri May 06 18:12:36 2016 -0700
@@ -423,6 +423,14 @@
         summary = ''
         if ctx.description():
             summary = ctx.description().splitlines()[0]
+
+        fword = summary.split(' ', 1)[0].lower()
+        # if it doesn't end with the special character '!' just skip this
+        if (self.repo.ui.configbool("experimental", "histedit.autoverb") and
+            initial and fword.endswith('!')):
+            fword = fword[:-1]
+            if fword in primaryactions | secondaryactions | tertiaryactions:
+                self.verb = fword
         line = '%s %s %d %s' % (self.verb, ctx, ctx.rev(), summary)
         # trim to 75 columns by default so it's not stupidly wide in my editor
         # (the 5 more are left for verb)
--- a/tests/test-histedit-arguments.t	Fri May 06 18:00:03 2016 -0700
+++ b/tests/test-histedit-arguments.t	Fri May 06 18:12:36 2016 -0700
@@ -499,3 +499,53 @@
   > EOF
   $ hg commit --amend -m 'allow this fold'
   $ hg histedit --continue
+
+  $ cd ..
+
+Test autoverb feature
+
+  $ hg init autoverb
+  $ cd autoverb
+  $ echo alpha >> alpha
+  $ hg addr
+  adding alpha
+  $ hg ci -m one
+  $ echo alpha >> alpha
+  $ hg ci -m two
+  $ echo alpha >> alpha
+  $ hg ci -m "roll! three"
+
+  $ hg log --style compact --graph
+  @  2[tip]   1b0b0b04c8fe   1970-01-01 00:00 +0000   test
+  |    roll! three
+  |
+  o  1   579e40513370   1970-01-01 00:00 +0000   test
+  |    two
+  |
+  o  0   6058cbb6cfd7   1970-01-01 00:00 +0000   test
+       one
+  
+
+Check that 'roll' is selected by default
+
+  $ HGEDITOR=cat hg histedit 1 --config experimental.histedit.autoverb=True
+  pick 579e40513370 1 two
+  roll 1b0b0b04c8fe 2 roll! three
+  
+  # Edit history between 579e40513370 and 1b0b0b04c8fe
+  #
+  # Commits are listed from least to most recent
+  #
+  # You can reorder changesets by reordering the lines
+  #
+  # Commands:
+  #
+  #  e, edit = use commit, but stop for amending
+  #  m, mess = edit commit message without changing commit content
+  #  p, pick = use commit
+  #  d, drop = remove commit from history
+  #  f, fold = use commit, but combine it with the one above
+  #  r, roll = like fold, but discard this commit's description
+  #
+
+  $ cd ..