]> git.ipfire.org Git - thirdparty/git.git/commitdiff
git-gui: strip comments and consecutive empty lines from commit messages
authorOswald Buddenhagen <oswald.buddenhagen@gmx.de>
Tue, 13 Aug 2024 09:06:30 +0000 (11:06 +0200)
committerJohannes Sixt <j6t@kdbg.org>
Thu, 15 Aug 2024 14:10:23 +0000 (16:10 +0200)
This is also known as "washing". This is consistent with the behavior of
interactive git commit, which we should emulate as closely as possible
to avoid usability problems. This way commit message templates and
prepare hooks can be used properly, and comments from conflicted rebases
and merges are cleaned up without having to introduce special handling
for them.

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

index 11379f8ad355e2ea2a7cf1645bc31543508731ab..f00a634624294273917ae92a229d4e75bb065408 100644 (file)
@@ -209,6 +209,10 @@ You must stage at least 1 file before you can commit.
        #
        set msg [string trim [$ui_comm get 1.0 end]]
        regsub -all -line {[ \t\r]+$} $msg {} msg
+       # Strip comment lines
+       regsub -all {(^|\n)#[^\n]*} $msg {\1} msg
+       # Compress consecutive empty lines
+       regsub -all {\n{3,}} $msg "\n\n" msg
        if {$msg eq {}} {
                error_popup [mc "Please supply a commit message.