git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] git-gui: highlight comment lines in commit message

From
WFWolfgang Faust <contrib-git@wolfgangfaust.com>
Date
Mar 1, 2026, 21:55 UTC
Message-ID
<a72715e2-c3ae-4050-95e3-7fc7f9b74b5d@app.fastmail.com>
These lines are stripped by wash_commit_message, but there is no indication
in the UI that they are special and will be removed.
Add highlighting to make it clear these lines are special.
Signed-off-by: Wolfgang Faust <contrib-git@wolfgangfaust.com>
(I'm not very good with tcl, so I suspect this code could use some work.
In particular the regex being a mangled copy of the one in the wash
procedure seems like a code smell, though I'm not sure how to improve
it.)  
---
 git-gui/git-gui.sh | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh
index d3d3aa14a9..3a0c08aa38 100755
--- a/git-gui/git-gui.sh
+++ b/git-gui/git-gui.sh
@@ -3900,6 +3900,25 @@ if {[winfo exists $ui_comm]} {

     backup_commit_buffer

+    # Grey out comment lines (which are stripped from the final
commit message by
+    # wash_commit_message).
+    $ui_comm tag configure commit_comment -foreground gray
+    proc highlight_commit_comment_lines {} {
+        global ui_comm comment_string
+        $ui_comm tag remove commit_comment 0.0 end
+        set text [$ui_comm get 1.0 end]
+        # See also cmt_rx in wash_commit_message
+        set cmt_rx [strcat {(?:^|\n)(} [regsub -all {\W}
$comment_string {\\&}] {[^\n]*)}]
+        set ranges [regexp -all -indices -inline -- $cmt_rx $text]
+        for {set i 1} {$i < [llength $ranges]} {incr i 2} {
+            $ui_comm tag add commit_comment \
+                [$ui_comm index "1.0 + [lindex [lindex $ranges $i] 0] chars"] \
+                [$ui_comm index "1.0 + [lindex [lindex $ranges $i] 0]
chars lineend + 1 char"]
+        }
+    }
+    highlight_commit_comment_lines
+    bind $ui_comm <<Modified>> { after idle highlight_commit_comment_lines }
+
     # -- If the user has aspell available we can drive it
     #    in pipe mode to spellcheck the commit message.
     #

base-commit: 7b2bccb0d58d4f24705bf985de1f4612e4cf06e5
-- 
2.52.0
Next: Johannes Sixt
Message 1 of 4 in “git-gui: highlight comment lines in commit message”
  1. git-gui: highlight comment lines in commit messageWolfgang Faust, Mar 1, 2026
  2. Johannes SixtMar 2, 2026
  3. Wolfgang FaustMar 4, 2026
  4. Johannes SixtMar 4, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.