Skip to content

Commit 4e55d19

Browse files
committed
git-gui: Cleanup end-of-line whitespace in commit messages.
When committing changes its useless to have trailing whitespace on the end of a line within the commit message itself; this serves no purpose beyond wasting space in the repository. But it happens a lot on my Mac OS X system if I copy text out of a Terminal.app window and paste it into git-gui. We now clip any trailing whitespace from the commit buffer when loading it from a file, when saving it out to our backup file, or when making the actual commit object. I also fixed a bug where we lost the commit message buffer if you quit without editing the text region. This can happen if you quit and restart git-gui frequently in the middle of an editing session. Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent 30b14ed commit 4e55d19

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

git-gui.sh

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ proc load_message {file} {
428428
}
429429
set content [string trim [read $fd]]
430430
close $fd
431+
regsub -all -line {[ \r\t]+$} $content {} content
431432
$ui_comm delete 0.0 end
432433
$ui_comm insert end $content
433434
return 1
@@ -1046,6 +1047,7 @@ You must add at least 1 file before you can commit.
10461047
# -- A message is required.
10471048
#
10481049
set msg [string trim [$ui_comm get 1.0 end]]
1050+
regsub -all -line {[ \t\r]+$} $msg {} msg
10491051
if {$msg eq {}} {
10501052
error_popup {Please supply a commit message.
10511053

@@ -2984,12 +2986,13 @@ proc do_quit {} {
29842986
#
29852987
set save [gitdir GITGUI_MSG]
29862988
set msg [string trim [$ui_comm get 0.0 end]]
2987-
if {![string match amend* $commit_type]
2988-
&& [$ui_comm edit modified]
2989+
regsub -all -line {[ \r\t]+$} $msg {} msg
2990+
if {(![string match amend* $commit_type]
2991+
|| [$ui_comm edit modified])
29892992
&& $msg ne {}} {
29902993
catch {
29912994
set fd [open $save w]
2992-
puts $fd [string trim [$ui_comm get 0.0 end]]
2995+
puts -nonewline $fd $msg
29932996
close $fd
29942997
}
29952998
} else {

0 commit comments

Comments
 (0)