aboutsummaryrefslogtreecommitdiff
path: root/lisp/magit-commit.el
diff options
context:
space:
mode:
authorJonas Bernoulli <jonas@bernoul.li>2025-01-17 07:45:31 +0100
committerJonas Bernoulli <jonas@bernoul.li>2025-01-17 07:45:31 +0100
commitae2218b3c9f809fa82e4b317ae77d67189b20911 (patch)
tree7326451c79591d261957f24bbb0df0cdafd2e0e8 /lisp/magit-commit.el
parent3a23ce5f5089c1b2e35ed5e03f660f65901b8529 (diff)
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.
Diffstat (limited to 'lisp/magit-commit.el')
-rw-r--r--lisp/magit-commit.el47
1 files changed, 37 insertions, 10 deletions
diff --git a/lisp/magit-commit.el b/lisp/magit-commit.el
index 78c39d2..681c7c6 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)]
@@ -269,6 +273,17 @@ then use `magit-commit-augment' instead of this command."
(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.