]> git.ipfire.org Git - thirdparty/git.git/commitdiff
git-gui: Only touch GITGUI_MSG when needed
authorPratyush Yadav <me@yadavpratyush.com>
Fri, 27 Nov 2020 10:23:51 +0000 (15:53 +0530)
committerPratyush Yadav <me@yadavpratyush.com>
Fri, 27 Nov 2020 14:36:38 +0000 (20:06 +0530)
In 4e55d19 (git-gui: Cleanup end-of-line whitespace in commit messages.,
2007-01-25), the logic to decide if GITGUI_MSG should be saved or
deleted was updated to not require the commit message buffer to be
modified. This fixes a situation where if the user quits and restarts
git-gui multiple times the commit message buffer was lost.

Unfortunately, the fix was not quite correct. The check for whether the
commit message buffer has been modified is useless. If the commit is
_not_ amend, then the check is never performed. If the commit is amend,
then saving the message does not matter anyway. Amend state is destroyed
on exit and the next time git-gui is opened it starts from scratch, but
with the older message retained in the buffer. If amend is selected,
the current message is over-written by the amend commit's message.

The correct fix would be to not touch GITGUI_MSG at all if the commit
message buffer is not modified. This way, the file is not deleted even
on multiple restarts. It has the added benefit of not writing the file
unnecessarily on every exit.

Signed-off-by: Pratyush Yadav <me@yadavpratyush.com>
git-gui.sh

index 867b8cea4618360b98b78125b2507ed4bd9e1872..8ee67e6f09771bf3ad0e878126c3aa3ac1c85f62 100755 (executable)
@@ -2305,11 +2305,10 @@ proc do_quit {{rc {1}}} {
                if {$GITGUI_BCK_exists && ![$ui_comm edit modified]} {
                        file rename -force [gitdir GITGUI_BCK] $save
                        set GITGUI_BCK_exists 0
-               } else {
+               } elseif {[$ui_comm edit modified]} {
                        set msg [string trim [$ui_comm get 0.0 end]]
                        regsub -all -line {[ \r\t]+$} $msg {} msg
-                       if {(![string match amend* $commit_type]
-                               || [$ui_comm edit modified])
+                       if {![string match amend* $commit_type]
                                && $msg ne {}} {
                                catch {
                                        set fd [open $save w]