branch: elpa/magit
commit ae2218b3c9f809fa82e4b317ae77d67189b20911
Author: Jonas Bernoulli <[email protected]>
Commit: Jonas Bernoulli <[email protected]>
magit-commit-{alter,revise}: New commands
- Bind "A" to `magit-commit-alter'. Previously that was bound to
`magit-commit-augment', but the new command is more similar to
`magit-commit-amend', whose binding is "a". `amend' and `alter' do
the approximately same thing, but the former is limited to the "HEAD"
commit. Additionally `alter' needs changes (else use `revise').
- Bind "W" to `magit-commit-revise' because "w" is bound to
`magit-commit-reword' and these two are also HEAD/any variants.
- Bind "n" to `magit-commit-augment'. The mnemonic being that this
adds a "note", which we later have to take into account when writing
the final commit message.
- Bind "d" to `magit-commit-reshelve' because "n" is now taken. Use
"d" because it changes dates. This command is disabled by default.
- In the menu, arrange the variants in a way that hopefully makes
these relations more obvious. Unfortunately this is not possible
without leaving some "table cells" empty.
---
CHANGELOG | 4 +++-
docs/magit.org | 19 ++++++++++++++++++-
docs/magit.texi | 21 ++++++++++++++++++++-
lisp/magit-commit.el | 47 +++++++++++++++++++++++++++++++++++++----------
4 files changed, 78 insertions(+), 13 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
index 5e39d078ae8..1ab667411dd 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -17,7 +17,9 @@
complete commit messages. f54fce0ecc..b86fe009e2
- ~amend!~ markers are now highlighted like ~fixup!~ and ~squash!~ markers.
- 6efe13e701
+ #5261
+
+- Added new commands ~magit-commit-alter~ and ~magit-commit-revise~. #5261
Bug fixes:
diff --git a/docs/magit.org b/docs/magit.org
index 96c1e4a9d87..a7436be2708 100644
--- a/docs/magit.org
+++ b/docs/magit.org
@@ -4670,7 +4670,15 @@ Also see [[man:git-commit]]
Create a squash commit and instantly rebase.
-- Key: c A (magit-commit-augment) ::
+- Key: c A (magit-commit-alter) ::
+
+ Create a squash commit, finalizing the message up front.
+
+ With a prefix argument the target COMMIT has to be confirmed.
+ Otherwise the commit at point may be used without confirmation
+ depending on the value of option ~magit-commit-squash-confirm~.
+
+- Key: c n (magit-commit-augment) ::
Create a squash commit, editing the squash message.
@@ -4678,6 +4686,15 @@ Also see [[man:git-commit]]
Otherwise the commit at point may be used without confirmation
depending on the value of option ~magit-commit-squash-confirm~.
+- Key: c A (magit-commit-revise) ::
+
+ Reword the message of commit other than the last, without editing
+ its tree.
+
+ With a prefix argument the target commit has to be confirmed.
+ Otherwise the commit at point may be used without confirmation
+ depending on the value of option ~magit-commit-squash-confirm~.
+
- User Option: magit-commit-ask-to-stage ::
Whether to ask to stage all unstaged changes when committing and nothing is
diff --git a/docs/magit.texi b/docs/magit.texi
index 69342c3808b..f0994ba0e14 100644
--- a/docs/magit.texi
+++ b/docs/magit.texi
@@ -5551,11 +5551,30 @@ depending on the value of option
@code{magit-commit-squash-confirm}.
@findex magit-commit-instant-squash
Create a squash commit and instantly rebase.
-@item @kbd{c A} (@code{magit-commit-augment})
+@item @kbd{c A} (@code{magit-commit-alter})
@kindex c A
+@findex magit-commit-alter
+Create a squash commit, finalizing the message up front.
+
+With a prefix argument the target COMMIT has to be confirmed.
+Otherwise the commit at point may be used without confirmation
+depending on the value of option @code{magit-commit-squash-confirm}.
+
+@item @kbd{c n} (@code{magit-commit-augment})
+@kindex c n
@findex magit-commit-augment
Create a squash commit, editing the squash message.
+With a prefix argument the target commit has to be confirmed.
+Otherwise the commit at point may be used without confirmation
+depending on the value of option @code{magit-commit-squash-confirm}.
+
+@item @kbd{c A} (@code{magit-commit-revise})
+@kindex c A
+@findex magit-commit-revise
+Reword the message of commit other than the last, without editing
+its tree.
+
With a prefix argument the target commit has to be confirmed.
Otherwise the commit at point may be used without confirmation
depending on the value of option @code{magit-commit-squash-confirm}.
diff --git a/lisp/magit-commit.el b/lisp/magit-commit.el
index 78c39d249d5..681c7c6b61a 100644
--- a/lisp/magit-commit.el
+++ b/lisp/magit-commit.el
@@ -135,13 +135,17 @@ Also see https://github.com/magit/magit/issues/4132."
("c" "Commit" magit-commit-create)]
["Edit HEAD"
("e" "Extend" magit-commit-extend)
- ("w" "Reword" magit-commit-reword)
+ ""
("a" "Amend" magit-commit-amend)
- ("n" "Reshelve" magit-commit-reshelve :level 0)]
+ ""
+ ("w" "Reword" magit-commit-reword)
+ ("d" "Reshelve" magit-commit-reshelve :level 0)]
["Edit"
("f" "Fixup" magit-commit-fixup)
("s" "Squash" magit-commit-squash)
- ("A" "Augment" magit-commit-augment)]
+ ("A" "Alter" magit-commit-alter)
+ ("n" "Augment" magit-commit-augment)
+ ("W" "Revise" magit-commit-revise)]
["Edit and rebase"
("F" "Instant fixup" magit-commit-instant-fixup)
("S" "Instant squash" magit-commit-instant-squash)]
@@ -268,6 +272,17 @@ then use `magit-commit-augment' instead of this command."
(magit-commit-arguments)))
(magit-commit-squash-internal "--squash=" commit args))
+;;;###autoload
+(defun magit-commit-alter (&optional commit args)
+ "Create a squash commit, finalizing the message up front.
+
+With a prefix argument the target COMMIT has to be confirmed.
+Otherwise the commit at point may be used without confirmation
+depending on the value of option `magit-commit-squash-confirm'."
+ (interactive (list (magit-commit-at-point)
+ (magit-commit-arguments)))
+ (magit-commit-squash-internal "--fixup=amend:" commit args nil 'edit))
+
;;;###autoload
(defun magit-commit-augment (&optional commit args)
"Create a squash commit, editing the squash message.
@@ -277,25 +292,36 @@ Otherwise the commit at point may be used without
confirmation
depending on the value of option `magit-commit-squash-confirm'."
(interactive (list (magit-commit-at-point)
(magit-commit-arguments)))
- (magit-commit-squash-internal "--squash=" commit args 'edit))
+ (magit-commit-squash-internal "--squash=" commit args nil 'edit))
+
+;;;###autoload
+(defun magit-commit-revise (&optional commit args)
+ "Reword the message of commit other than the last, without editing its tree.
+
+With a prefix argument the target COMMIT has to be confirmed.
+Otherwise the commit at point may be used without confirmation
+depending on the value of option `magit-commit-squash-confirm'."
+ (interactive (list (magit-commit-at-point)
+ (magit-commit-arguments)))
+ (magit-commit-squash-internal "--fixup=reword:" commit args 'nopatch 'edit))
;;;###autoload
(defun magit-commit-instant-fixup (&optional commit args)
"Create a fixup commit targeting COMMIT and instantly rebase."
(interactive (list (magit-commit-at-point)
(magit-commit-arguments)))
- (magit-commit-squash-internal "--fixup=" commit args nil 'rebase))
+ (magit-commit-squash-internal "--fixup=" commit args nil nil 'rebase))
;;;###autoload
(defun magit-commit-instant-squash (&optional commit args)
"Create a squash commit targeting COMMIT and instantly rebase."
(interactive (list (magit-commit-at-point)
(magit-commit-arguments)))
- (magit-commit-squash-internal "--squash=" commit args nil 'rebase))
+ (magit-commit-squash-internal "--squash=" commit args nil nil 'rebase))
(defun magit-commit-squash-internal
- (option commit &optional args edit rebase confirmed)
- (when-let ((args (magit-commit-assert args (not edit))))
+ (option commit &optional args nopatch edit rebase confirmed)
+ (when-let ((args (magit-commit-assert args nopatch (not edit))))
(when (and commit rebase (not (magit-rev-ancestor-p commit "HEAD")))
(magit-read-char-case
(format "%s isn't an ancestor of HEAD. " commit) nil
@@ -326,7 +352,7 @@ depending on the value of option
`magit-commit-squash-confirm'."
(magit-log-select
(lambda (commit)
(when (and (magit-commit-squash-internal option commit args
- edit rebase t)
+ nopatch edit rebase t)
rebase)
(magit-commit-amend-assert commit)
(magit-rebase-interactive-1 commit
@@ -350,8 +376,9 @@ depending on the value of option
`magit-commit-squash-confirm'."
(concat m1 "%d public branches" m2)
nil branches))))
-(defun magit-commit-assert (args &optional strict)
+(defun magit-commit-assert (args &optional nopatch strict)
(cond
+ (nopatch args)
((or (magit-anything-staged-p)
(and (magit-anything-unstaged-p)
;; ^ Everything of nothing is still nothing.