Skip to content

Commit 6b43a57

Browse files
ossilatorj6t
authored andcommitted
git-gui: heed core.commentChar/commentString
This amends 1ae85ff (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 <[email protected]> Signed-off-by: Johannes Sixt <[email protected]>
1 parent 9093496 commit 6b43a57

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

git-gui.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -880,6 +880,12 @@ proc apply_config {} {
880880
color::sync_with_theme
881881
}
882882
}
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+
}
883889
}
884890

885891
set default_config(branch.autosetupmerge) true
@@ -890,6 +896,8 @@ set default_config(merge.summary) false
890896
set default_config(merge.verbosity) 2
891897
set default_config(user.name) {}
892898
set default_config(user.email) {}
899+
set default_config(core.commentchar) "#"
900+
set default_config(core.commentstring) {}
893901

894902
set default_config(gui.encoding) [encoding system]
895903
set default_config(gui.matchtrackingbranch) false

lib/commit.tcl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,9 @@ You must stage at least 1 file before you can commit.
211211
# Strip trailing whitespace
212212
regsub -all -line {[ \t\r]+$} $msg {} msg
213213
# 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
215217
# Strip leading empty lines
216218
regsub {^\n*} $msg {} msg
217219
# Compress consecutive empty lines

0 commit comments

Comments
 (0)