git-gui: heed core.commentChar/commentString

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>

Oswald Buddenhagen committed Mar 15, 2025 at 15:09 UTC 6b43a57dfce1e5acd85f7a8365c080b6fc4f8645
2 files changed +11 -1
git-gui.sh
+8
@@ -880,6 +880,12 @@ proc apply_config {} {
880 color::sync_with_theme
881 }
882 }
883 +
884 + global comment_string
885 + set comment_string [get_config core.commentstring]
886 + if {$comment_string eq {}} {
887 + set comment_string [get_config core.commentchar]
888 + }
889 }
890
891 set default_config(branch.autosetupmerge) true
@@ -890,6 +896,8 @@ set default_config(merge.summary) false
896 set default_config(merge.verbosity) 2
897 set default_config(user.name) {}
898 set default_config(user.email) {}
899 +set default_config(core.commentchar) "#"
900 +set default_config(core.commentstring) {}
901
902 set default_config(gui.encoding) [encoding system]
903 set default_config(gui.matchtrackingbranch) false
lib/commit.tcl
+3 -1
@@ -211,7 +211,9 @@ You must stage at least 1 file before you can commit.
211 # Strip trailing whitespace
212 regsub -all -line {[ \t\r]+$} $msg {} msg
213 # Strip comment lines
214 - regsub -all {(^|\n)#[^\n]*} $msg {\1} msg
214 + global comment_string
215 + set cmt_rx [strcat {(^|\n)} [regsub -all {\W} $comment_string {\\&}] {[^\n]*}]
216 + regsub -all $cmt_rx $msg {\1} msg
217 # Strip leading empty lines
218 regsub {^\n*} $msg {} msg
219 # Compress consecutive empty lines