Skip to content

Commit fda1ba0

Browse files
committed
git-gui: preserve commit messages in utf-8
The commit message buffer is automatically preserved to a local file but this uses the system encoding which may fail to properly encode unicode text. Forcing this file to use utf-8 preserves the message correctly. Reported-by: Ángel José Riesgo <[email protected]> Signed-off-by: Pat Thoyts <[email protected]>
1 parent c42939d commit fda1ba0

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

git-gui.sh

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,7 +1464,7 @@ proc rescan {after {honor_trustmtime 1}} {
14641464
(![$ui_comm edit modified]
14651465
|| [string trim [$ui_comm get 0.0 end]] eq {})} {
14661466
if {[string match amend* $commit_type]} {
1467-
} elseif {[load_message GITGUI_MSG]} {
1467+
} elseif {[load_message GITGUI_MSG utf-8]} {
14681468
} elseif {[run_prepare_commit_msg_hook]} {
14691469
} elseif {[load_message MERGE_MSG]} {
14701470
} elseif {[load_message SQUASH_MSG]} {
@@ -1550,7 +1550,7 @@ proc rescan_stage2 {fd after} {
15501550
fileevent $fd_lo readable [list read_ls_others $fd_lo $after]
15511551
}
15521552
1553-
proc load_message {file} {
1553+
proc load_message {file {encoding {}}} {
15541554
global ui_comm
15551555
15561556
set f [gitdir $file]
@@ -1559,6 +1559,9 @@ proc load_message {file} {
15591559
return 0
15601560
}
15611561
fconfigure $fd -eofchar {}
1562+
if {$encoding ne {}} {
1563+
fconfigure $fd -encoding $encoding
1564+
}
15621565
set content [string trim [read $fd]]
15631566
close $fd
15641567
regsub -all -line {[ \r\t]+$} $content {} content
@@ -2267,6 +2270,7 @@ proc do_quit {{rc {1}}} {
22672270
&& $msg ne {}} {
22682271
catch {
22692272
set fd [open $save w]
2273+
fconfigure $fd -encoding utf-8
22702274
puts -nonewline $fd $msg
22712275
close $fd
22722276
}
@@ -3836,7 +3840,7 @@ if {[is_enabled transport]} {
38363840
}
38373841
38383842
if {[winfo exists $ui_comm]} {
3839-
set GITGUI_BCK_exists [load_message GITGUI_BCK]
3843+
set GITGUI_BCK_exists [load_message GITGUI_BCK utf-8]
38403844
38413845
# -- If both our backup and message files exist use the
38423846
# newer of the two files to initialize the buffer.
@@ -3873,6 +3877,7 @@ if {[winfo exists $ui_comm]} {
38733877
} elseif {$m} {
38743878
catch {
38753879
set fd [open [gitdir GITGUI_BCK] w]
3880+
fconfigure $fd -encoding utf-8
38763881
puts -nonewline $fd $msg
38773882
close $fd
38783883
set GITGUI_BCK_exists 1

0 commit comments

Comments
 (0)