aboutsummaryrefslogtreecommitdiff
path: root/lisp/git-rebase.el
diff options
context:
space:
mode:
authorJonas Bernoulli <jonas@bernoul.li>2025-07-09 20:07:14 +0200
committerJonas Bernoulli <jonas@bernoul.li>2025-07-09 20:07:14 +0200
commitf5eb9831353d86d015c63b804a1dc4afe342d99a (patch)
tree4b2daf2337054d59e8e9dbf334b236163c13d11c /lisp/git-rebase.el
parent9b6b41654e7ea38a2213a7b3a224c20839672df4 (diff)
rebase: Deal with comment character in the middle of action lines
In "merge" lines the description was always prefixed with "# ". Since Git v2.50.0 that is also done for other action lines. To support older releases, "# " has to be optional for these other action lines. While that isn't necessary, make it optional for "merge" lines as well. Note that Git always uses "#"; `core.commentChar' does not control the character used here. Never-the-less start using `font-lock-comment-face' for this inline "#"; frankly it is unnecessary noise that is best diminished.
Diffstat (limited to 'lisp/git-rebase.el')
-rw-r--r--lisp/git-rebase.el24
1 files changed, 16 insertions, 8 deletions
diff --git a/lisp/git-rebase.el b/lisp/git-rebase.el
index fc61ad4..2080a6e 100644
--- a/lisp/git-rebase.el
+++ b/lisp/git-rebase.el
@@ -321,6 +321,8 @@ region is active, act on all lines touched by the region."
(abbrev)))
(defvar git-rebase-line-regexps
+ ;; 1: action, 2: option, 3: target, 4: "#", 5: description.
+ ;;
;; <action> <commit> [[# ] <oneline>]
;; fixup [-C|-c] <commit> [[# ] <oneline>]
`((commit . ,(concat
@@ -334,7 +336,7 @@ region is active, act on all lines touched by the region."
"s" "squash")
"\\(?1:")
" \\(?3:[^ \n]+\\)"
- "\\(?: \\(?4:.*\\)\\)?"))
+ "\\(?: \\(?4:# \\)?\\(?5:.*\\)\\)?"))
(exec . "\\(?1:x\\|exec\\) \\(?3:.*\\)")
(bare . ,(concat (regexp-opt '("b" "break" "noop") "\\(?1:")
" *$"))
@@ -343,13 +345,13 @@ region is active, act on all lines touched by the region."
"u" "update-ref")
"\\(?1:")
" \\(?3:[^ \n]+\\)"
- "\\(?: \\(?4:.*\\)\\)?"))
+ "\\(?: \\(?4:# \\)?\\(?5:.*\\)\\)?"))
;; merge [-C <commit> | -c <commit>] <label> [# <oneline>]
;; <commit> is matched by group 22 (part of group 2), not group 3
(merge . ,(concat "\\(?1:m\\|merge\\) "
"\\(?:\\(?2:\\(?21:-[cC]\\) \\(?22:[^ \n]+\\)\\) \\)?"
"\\(?3:[^ \n]+\\)"
- "\\(?: # \\(?4:.*\\)\\)?"))))
+ "\\(?: \\(?4:# \\)?\\(?5:.*\\)\\)?"))))
;;;###autoload
(defun git-rebase-current-line (&optional batch)
@@ -375,7 +377,7 @@ BATCH also ignores commented lines."
action))
:action-options (match-string-no-properties 2)
:target (match-string-no-properties 3)
- :trailer (match-string-no-properties 4)
+ :trailer (match-string-no-properties 5)
:comment-p (and (match-string 99) t))
(and (not batch)
;; Use empty object rather than nil to ease handling.
@@ -400,7 +402,10 @@ of its action type."
((and action (eq action-type 'commit))
(let ((inhibit-read-only t))
(magit-delete-line)
- (insert (concat action " " target " " trailer "\n"))))
+ (insert (concat action " " target " "))
+ (when (magit-git-version>= "2.50.0")
+ (insert "# "))
+ (insert (concat trailer "\n"))))
((and (not action) action-type)
(let ((inhibit-read-only t))
(if comment-p
@@ -810,7 +815,8 @@ running \"man git-rebase\" at the command line) for details."
`((,(concat "^" (cdr (assq 'commit git-rebase-line-regexps)))
(1 'git-rebase-action)
(3 'git-rebase-hash)
- (4 'git-rebase-description nil t))
+ (4 'font-lock-comment-face nil t)
+ (5 'git-rebase-description nil t))
(,(concat "^" (cdr (assq 'exec git-rebase-line-regexps)))
(1 'git-rebase-action)
(3 'git-rebase-description))
@@ -819,13 +825,15 @@ running \"man git-rebase\" at the command line) for details."
(,(concat "^" (cdr (assq 'label git-rebase-line-regexps)))
(1 'git-rebase-action)
(3 'git-rebase-label)
- (4 'git-rebase-description nil t))
+ (4 'font-lock-comment-face nil t)
+ (5 'git-rebase-description nil t))
(,(concat "^" (cdr (assq 'merge git-rebase-line-regexps)))
(1 'git-rebase-action)
(21 'git-rebase-action nil t)
(22 'git-rebase-hash t t)
(3 'git-rebase-label)
- (4 'git-rebase-description nil t))
+ (4 'font-lock-comment-face nil t)
+ (5 'git-rebase-description nil t))
("^drop \\(.+\\)"
(1 'git-rebase-killed-action t))
(,(concat git-rebase-comment-re " *"