Skip to content

Commit

Permalink
Merge branch 'os/catch-rename'
Browse files Browse the repository at this point in the history
The problem can be reproduced on Linux with this sequence:

1. Run git gui from a terminal.
2. Edit the commit message and wait for at least 2 seconds.
3. Terminate the instance from the terminal, for example with Ctrl-C,
   to simulate crash. This leaves the file .git/GITGUI_BCK behind.
4. Start two instances of git gui &.

At this point the first instance can be closed (it renames
.git/GITGUI_BCK to .git/GITGUI_MSG), but the seconds brings an error
message about the absent file and cannot be closed thereafter and must
be killed from the command line.

The renaming that happens by the first instance is the correct action
and need not be repeated by the second instance. It is the correct
action to ignore the failed renaming.

On the other hand, the second instance could just edit the commit
message again, wait 2 seconds to write GITGUI_BCK, and then can be
closed without failing. At this point, since the user has edited the
message, it is again correct to preserve the edited version in
GITGUI_MSG.

* os/catch-rename:
  git-gui: fix inability to quit after closing another instance
  • Loading branch information
j6t committed Jul 7, 2024
2 parents c1db988 + f402c79 commit 2864e85
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion git-gui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2301,7 +2301,7 @@ proc do_quit {{rc {1}}} {
#
set save [gitdir GITGUI_MSG]
if {$GITGUI_BCK_exists && ![$ui_comm edit modified]} {
file rename -force [gitdir GITGUI_BCK] $save
catch { file rename -force [gitdir GITGUI_BCK] $save }
set GITGUI_BCK_exists 0
} elseif {[$ui_comm edit modified]} {
set msg [string trim [$ui_comm get 0.0 end]]
Expand Down

0 comments on commit 2864e85

Please sign in to comment.