mirror of
https://github.com/facebook/sapling.git
synced 2024-10-06 23:07:18 +03:00
commit: add amend mode for commit -i
When I moved crecord into core, I didn't include the toggleAmend function (to switch from commit to amend mode). I did it because it would have made it more difficult to use record and crecord interchangably. This patch reintroduces the amend mode for commit -i as well as two tests to verify the behavior of the function.
This commit is contained in:
parent
1409af5e69
commit
37960d39f4
@ -24,6 +24,7 @@ from . import (
|
||||
encoding,
|
||||
error,
|
||||
patch as patchmod,
|
||||
util,
|
||||
)
|
||||
|
||||
# This is required for ncurses to display non-ASCII characters in default user
|
||||
@ -1010,7 +1011,7 @@ class curseschunkselector(object):
|
||||
pairname="legend")
|
||||
printstring(self.statuswin,
|
||||
" (f)old/unfold; (c)onfirm applied; (q)uit; (?) help "
|
||||
"| [X]=hunk applied **=folded",
|
||||
"| [X]=hunk applied **=folded, toggle [a]mend mode",
|
||||
pairname="legend")
|
||||
except curses.error:
|
||||
pass
|
||||
@ -1366,7 +1367,7 @@ the following are valid keystrokes:
|
||||
F : fold / unfold parent item and all of its ancestors
|
||||
m : edit / resume editing the commit message
|
||||
e : edit the currently selected hunk
|
||||
a : toggle amend mode (hg rev >= 2.2)
|
||||
a : toggle amend mode (hg rev >= 2.2), only with commit -i
|
||||
c : confirm selected changes
|
||||
r : review/edit and confirm selected changes
|
||||
q : quit without confirming (no changes will be made)
|
||||
@ -1433,6 +1434,35 @@ are you sure you want to review/edit and confirm the selected changes [yn]?
|
||||
else:
|
||||
return False
|
||||
|
||||
def toggleamend(self, opts, test):
|
||||
"""Toggle the amend flag.
|
||||
|
||||
When the amend flag is set, a commit will modify the most recently
|
||||
committed changeset, instead of creating a new changeset. Otherwise, a
|
||||
new changeset will be created (the normal commit behavior).
|
||||
|
||||
"""
|
||||
try:
|
||||
ver = float(util.version()[:3])
|
||||
except ValueError:
|
||||
ver = 1
|
||||
if ver < 2.19:
|
||||
msg = ("The amend option is unavailable with hg versions < 2.2\n\n"
|
||||
"Press any key to continue.")
|
||||
elif opts.get('amend') is None:
|
||||
opts['amend'] = True
|
||||
msg = ("Amend option is turned on -- commiting the currently "
|
||||
"selected changes will not create a new changeset, but "
|
||||
"instead update the most recently committed changeset.\n\n"
|
||||
"Press any key to continue.")
|
||||
elif opts.get('amend') is True:
|
||||
opts['amend'] = None
|
||||
msg = ("Amend option is turned off -- commiting the currently "
|
||||
"selected changes will create a new changeset.\n\n"
|
||||
"Press any key to continue.")
|
||||
if not test:
|
||||
self.confirmationwindow(msg)
|
||||
|
||||
def recenterdisplayedarea(self):
|
||||
"""
|
||||
once we scrolled with pg up pg down we can be pointing outside of the
|
||||
@ -1570,6 +1600,8 @@ are you sure you want to review/edit and confirm the selected changes [yn]?
|
||||
self.leftarrowshiftevent()
|
||||
elif keypressed in ["q"]:
|
||||
raise error.Abort(_('user quit'))
|
||||
elif keypressed in ['a']:
|
||||
self.toggleamend(self.opts, test)
|
||||
elif keypressed in ["c"]:
|
||||
if self.confirmcommit():
|
||||
return True
|
||||
|
@ -71,6 +71,7 @@ Committing only one hunk while aborting edition of hunk
|
||||
- unfold it
|
||||
- go down to second hunk (1 for the first hunk, 1 for the first hunkline, 1 for the second hunk, 1 for the second hunklike)
|
||||
- toggle the second hunk
|
||||
- toggle on and off the amend mode (to check that it toggles off)
|
||||
- edit the hunk and quit the editor immediately with non-zero status
|
||||
- commit
|
||||
|
||||
@ -88,6 +89,8 @@ Committing only one hunk while aborting edition of hunk
|
||||
> KEY_DOWN
|
||||
> KEY_DOWN
|
||||
> TOGGLE
|
||||
> a
|
||||
> a
|
||||
> e
|
||||
> X
|
||||
> EOF
|
||||
@ -166,3 +169,23 @@ Newly added files can be selected with the curses interface
|
||||
$ hg st
|
||||
? testModeCommands
|
||||
|
||||
Amend option works
|
||||
$ echo "hello world" > x
|
||||
$ hg diff -c .
|
||||
diff -r a6735021574d -r 2b0e9be4d336 x
|
||||
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
|
||||
+++ b/x Thu Jan 01 00:00:00 1970 +0000
|
||||
@@ -0,0 +1,1 @@
|
||||
+hello
|
||||
$ cat <<EOF >testModeCommands
|
||||
> a
|
||||
> X
|
||||
> EOF
|
||||
$ hg commit -i -m "newly added file" -d "0 0"
|
||||
saved backup bundle to $TESTTMP/a/.hg/strip-backup/2b0e9be4d336-28bbe4e2-amend-backup.hg (glob)
|
||||
$ hg diff -c .
|
||||
diff -r a6735021574d -r c1d239d165ae x
|
||||
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
|
||||
+++ b/x Thu Jan 01 00:00:00 1970 +0000
|
||||
@@ -0,0 +1,1 @@
|
||||
+hello world
|
||||
|
Loading…
Reference in New Issue
Block a user