git-gui: Optionally save commit buffer on exit.
If the commit area does not exist, don't save the commit message to a file, or the window geometry. The reason I'm doing this is I want to make the main window entirely optional, such as if the user has asked us to show a blame from the command line. In such cases the commit area won't exist and trying to get its text would cause an error. If we are running without the commit message area, we cannot save our window geometry either, as the root window '.' won't be a normal commit window. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed
Feb 8, 2007 at 17:47 UTC
db7f34d4c54c1162d976be4d1752642c85e063b4
1 file changed
+28
-26
git-gui.sh
+28
-26
@@ -4126,34 +4126,36 @@ proc do_quit {} {
4126
if {$is_quitting} return
4127
set is_quitting 1
4128
4129
- # -- Stash our current commit buffer.
4130
- #
4131
- set save [gitdir GITGUI_MSG]
4132
- set msg [string trim [$ui_comm get 0.0 end]]
4133
- regsub -all -line {[ \r\t]+$} $msg {} msg
4134
- if {(![string match amend* $commit_type]
4135
- || [$ui_comm edit modified])
4136
- && $msg ne {}} {
4137
- catch {
4138
- set fd [open $save w]
4139
- puts -nonewline $fd $msg
4140
- close $fd
4129
+ if {[winfo exists $ui_comm]} {
4130
+ # -- Stash our current commit buffer.
4131
+ #
4132
+ set save [gitdir GITGUI_MSG]
4133
+ set msg [string trim [$ui_comm get 0.0 end]]
4134
+ regsub -all -line {[ \r\t]+$} $msg {} msg
4135
+ if {(![string match amend* $commit_type]
4136
+ || [$ui_comm edit modified])
4137
+ && $msg ne {}} {
4138
+ catch {
4139
+ set fd [open $save w]
4140
+ puts -nonewline $fd $msg
4141
+ close $fd
4142
+ }
4143
+ } else {
4144
+ catch {file delete $save}
4145
}
4142
- } else {
4143
- catch {file delete $save}
4144
- }
4146
4146
- # -- Stash our current window geometry into this repository.
4147
- #
4148
- set cfg_geometry [list]
4149
- lappend cfg_geometry [wm geometry .]
4150
- lappend cfg_geometry [lindex [.vpane sash coord 0] 1]
4151
- lappend cfg_geometry [lindex [.vpane.files sash coord 0] 0]
4152
- if {[catch {set rc_geometry $repo_config(gui.geometry)}]} {
4153
- set rc_geometry {}
4154
- }
4155
- if {$cfg_geometry ne $rc_geometry} {
4156
- catch {exec git repo-config gui.geometry $cfg_geometry}
4147
+ # -- Stash our current window geometry into this repository.
4148
+ #
4149
+ set cfg_geometry [list]
4150
+ lappend cfg_geometry [wm geometry .]
4151
+ lappend cfg_geometry [lindex [.vpane sash coord 0] 1]
4152
+ lappend cfg_geometry [lindex [.vpane.files sash coord 0] 0]
4153
+ if {[catch {set rc_geometry $repo_config(gui.geometry)}]} {
4154
+ set rc_geometry {}
4155
+ }
4156
+ if {$cfg_geometry ne $rc_geometry} {
4157
+ catch {exec git repo-config gui.geometry $cfg_geometry}
4158
+ }
4159
}
4160
4161
destroy .