]> git.ipfire.org Git - thirdparty/git.git/commitdiff
git-gui: heed core.commentChar/commentString
authorOswald Buddenhagen <oswald.buddenhagen@gmx.de>
Sat, 15 Mar 2025 14:09:13 +0000 (15:09 +0100)
committerJohannes Sixt <j6t@kdbg.org>
Sun, 16 Mar 2025 12:51:55 +0000 (13:51 +0100)
This amends 1ae85ff6d (git-gui: strip comments and consecutive empty
lines from commit messages, 2024-08-13) to deal with custom comment
characters/strings.

The magic commentString value "auto" is not handled, because the option
makes no sense to me - it does not support comments in templates and
hook output, and it seems far-fetched that someone would introduce
comments during editing the message.

Signed-off-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de>
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
git-gui.sh
lib/commit.tcl

index 8fe7538e72084d1d794c88e00402602be7df7d65..2bc2c9b63e6e5c6d9deb4371e28939e304567692 100755 (executable)
@@ -880,6 +880,12 @@ proc apply_config {} {
                        color::sync_with_theme
                }
        }
+
+       global comment_string
+       set comment_string [get_config core.commentstring]
+       if {$comment_string eq {}} {
+               set comment_string [get_config core.commentchar]
+       }
 }
 
 set default_config(branch.autosetupmerge) true
@@ -890,6 +896,8 @@ set default_config(merge.summary) false
 set default_config(merge.verbosity) 2
 set default_config(user.name) {}
 set default_config(user.email) {}
+set default_config(core.commentchar) "#"
+set default_config(core.commentstring) {}
 
 set default_config(gui.encoding) [encoding system]
 set default_config(gui.matchtrackingbranch) false
index 208dc2817ca68c89a0e66464e40e01e007df99bd..a570f9cdc6a406ef9482802e16c4489cc9873c2c 100644 (file)
@@ -211,7 +211,9 @@ You must stage at least 1 file before you can commit.
        # Strip trailing whitespace
        regsub -all -line {[ \t\r]+$} $msg {} msg
        # Strip comment lines
-       regsub -all {(^|\n)#[^\n]*} $msg {\1} msg
+       global comment_string
+       set cmt_rx [strcat {(^|\n)} [regsub -all {\W} $comment_string {\\&}] {[^\n]*}]
+       regsub -all $cmt_rx $msg {\1} msg
        # Strip leading empty lines
        regsub {^\n*} $msg {} msg
        # Compress consecutive empty lines