git-gui: Misc. formatting cleanups.
[gitweb.git] / git-gui
diff --git a/git-gui b/git-gui
index 81fe38f0068335f2f3dba8abae905eb3cdd8db84..f8c51590b04a664bb5dd149d330d6ef44d37c665 100755 (executable)
--- a/git-gui
+++ b/git-gui
@@ -48,11 +48,9 @@ proc save_my_config {} {
                set repo_config(gui.trustmtime) [list $cfg_trust_mtime]
        }
 
-       set cfg_geometry [list \
-               [wm geometry .] \
-               [.vpane sash coord 0] \
-               [.vpane.files sash coord 0] \
-               ]
+       set cfg_geometry [wm geometry .]
+       append cfg_geometry " [lindex [.vpane sash coord 0] 1]"
+       append cfg_geometry " [lindex [.vpane.files sash coord 0] 0]"
        if {[catch {set rc_geometry $repo_config(gui.geometry)}]} {
                set rc_geometry [list [list]]
        }
@@ -73,7 +71,8 @@ proc error_popup {msg} {
                        end]
                append title {)}
        }
-       tk_messageBox -parent . \
+       tk_messageBox \
+               -parent . \
                -icon error \
                -type ok \
                -title "$title: error" \
@@ -84,8 +83,10 @@ proc error_popup {msg} {
 ##
 ## repository setup
 
-if {[catch {set cdup [exec git rev-parse --show-cdup]} err]} {
-       error_popup "Cannot find the git directory:\n$err"
+if {   [catch {set cdup [exec git rev-parse --show-cdup]} err]
+       || [catch {set gitdir [exec git rev-parse --git-dir]} err]} {
+       catch {wm withdraw .}
+       error_popup "Cannot find the git directory:\n\n$err"
        exit 1
 }
 if {$cdup != ""} {
@@ -93,11 +94,6 @@ if {$cdup != ""} {
 }
 unset cdup
 
-if {[catch {set gitdir [exec git rev-parse --git-dir]} err]} {
-       error_popup "Cannot find the git directory:\n$err"
-       exit 1
-}
-
 if {$appname == {git-citool}} {
        set single_commit 1
 }
@@ -201,7 +197,8 @@ proc update_status {{final Ready.}} {
                set ui_status_value {Refreshing file status...}
                set fd_rf [open "| git update-index -q --unmerged --refresh" r]
                fconfigure $fd_rf -blocking 0 -translation binary
-               fileevent $fd_rf readable [list update_status_stage2 $fd_rf $final]
+               fileevent $fd_rf readable \
+                       [list update_status_stage2 $fd_rf $final]
        }
 }
 
@@ -406,8 +403,6 @@ proc show_diff {path {w {}} {lno {}}} {
 
        set cmd [list | git diff-index -p $PARENT -- $path]
        switch $m {
-       AM {
-       }
        MM {
                set cmd [list | git diff-index -p -c $PARENT $path]
        }
@@ -420,7 +415,7 @@ proc show_diff {path {w {}} {lno {}}} {
                        set diff_active 0
                        unlock_index
                        set ui_status_value "Unable to display [escape_path $path]"
-                       error_popup "Error loading file:\n$err"
+                       error_popup "Error loading file:\n\n$err"
                        return
                }
                $ui_diff conf -state normal
@@ -437,7 +432,7 @@ proc show_diff {path {w {}} {lno {}}} {
                set diff_active 0
                unlock_index
                set ui_status_value "Unable to display [escape_path $path]"
-               error_popup "Error loading diff:\n$err"
+               error_popup "Error loading diff:\n\n$err"
                return
        }
 
@@ -523,7 +518,7 @@ proc load_last_commit {} {
                        set msg [string trim [read $fd]]
                        close $fd
                } err]} {
-               error_popup "Error loading commit data for amend:\n$err"
+               error_popup "Error loading commit data for amend:\n\n$err"
                return
        }
 
@@ -655,10 +650,8 @@ proc commit_stage2 {fd_wt curHEAD msg} {
        global file_states
 
        gets $fd_wt tree_id
-       close $fd_wt
-
-       if {$tree_id == {}} {
-               error_popup "write-tree failed"
+       if {$tree_id == {} || [catch {close $fd_wt} err]} {
+               error_popup "write-tree failed:\n\n$err"
                set commit_active 0
                set ui_status_value {Commit failed.}
                unlock_index
@@ -679,7 +672,7 @@ proc commit_stage2 {fd_wt curHEAD msg} {
                                }
                                close $fd_mh
                        } err]} {
-                       error_popup "Loading MERGE_HEAD failed:\n$err"
+                       error_popup "Loading MERGE_HEAD failed:\n\n$err"
                        set commit_active 0
                        set ui_status_value {Commit failed.}
                        unlock_index
@@ -692,7 +685,7 @@ proc commit_stage2 {fd_wt curHEAD msg} {
        }
        lappend cmd << $msg
        if {[catch {set cmt_id [eval exec $cmd]} err]} {
-               error_popup "commit-tree failed:\n$err"
+               error_popup "commit-tree failed:\n\n$err"
                set commit_active 0
                set ui_status_value {Commit failed.}
                unlock_index
@@ -713,7 +706,7 @@ proc commit_stage2 {fd_wt curHEAD msg} {
        }
        set cmd [list git update-ref -m $reflogm HEAD $cmt_id $curHEAD]
        if {[catch {eval exec $cmd} err]} {
-               error_popup "update-ref failed:\n$err"
+               error_popup "update-ref failed:\n\n$err"
                set commit_active 0
                set ui_status_value {Commit failed.}
                unlock_index
@@ -834,7 +827,8 @@ proc post_pull_remote {remote branch success} {
                set PARENT $HEAD
                set $ui_status_value {Ready.}
        } else {
-               update_status "Conflicts detected while pulling $branch from $remote."
+               update_status \
+                       "Conflicts detected while pulling $branch from $remote."
        }
 }
 
@@ -1426,8 +1420,13 @@ proc do_repack {} {
        console_exec $w $cmd
 }
 
+set quitting 0
+
 proc do_quit {} {
-       global gitdir ui_comm
+       global gitdir ui_comm quitting
+
+       if {$quitting} return
+       set quitting 1
 
        set save [file join $gitdir GITGUI_MSG]
        set msg [string trim [$ui_comm get 0.0 end]]
@@ -1481,12 +1480,12 @@ proc do_signoff {} {
 
        if {$GIT_COMMITTER_IDENT == {}} {
                if {[catch {set me [exec git var GIT_COMMITTER_IDENT]} err]} {
-                       error_popup "Unable to obtain your identity:\n$err"
+                       error_popup "Unable to obtain your identity:\n\n$err"
                        return
                }
                if {![regexp {^(.*) [0-9]+ [-+0-9]+$} \
                        $me me GIT_COMMITTER_IDENT]} {
-                       error_popup "Invalid GIT_COMMITTER_IDENT:\n$me"
+                       error_popup "Invalid GIT_COMMITTER_IDENT:\n\n$me"
                        return
                }
        }
@@ -1549,7 +1548,7 @@ set maincursor [. cget -cursor]
 switch -glob -- "$tcl_platform(platform),$tcl_platform(os)" {
 windows,*   {set M1B Control; set M1T Ctrl}
 unix,Darwin {set M1B M1; set M1T Cmd}
-default     {set M1B M1; set M1T M1}
+*           {set M1B M1; set M1T M1}
 }
 
 # -- Menu Bar
@@ -1721,19 +1720,22 @@ button .vpane.lower.commarea.buttons.rescan -text {Rescan} \
        -command do_rescan \
        -font $font_ui
 pack .vpane.lower.commarea.buttons.rescan -side top -fill x
-lappend disable_on_lock {.vpane.lower.commarea.buttons.rescan conf -state}
+lappend disable_on_lock \
+       {.vpane.lower.commarea.buttons.rescan conf -state}
 
 button .vpane.lower.commarea.buttons.amend -text {Amend Last} \
        -command do_amend_last \
        -font $font_ui
 pack .vpane.lower.commarea.buttons.amend -side top -fill x
-lappend disable_on_lock {.vpane.lower.commarea.buttons.amend conf -state}
+lappend disable_on_lock \
+       {.vpane.lower.commarea.buttons.amend conf -state}
 
 button .vpane.lower.commarea.buttons.incall -text {Include All} \
        -command do_include_all \
        -font $font_ui
 pack .vpane.lower.commarea.buttons.incall -side top -fill x
-lappend disable_on_lock {.vpane.lower.commarea.buttons.incall conf -state}
+lappend disable_on_lock \
+       {.vpane.lower.commarea.buttons.incall conf -state}
 
 button .vpane.lower.commarea.buttons.signoff -text {Sign Off} \
        -command do_signoff \
@@ -1744,7 +1746,8 @@ button .vpane.lower.commarea.buttons.commit -text {Commit} \
        -command do_commit \
        -font $font_ui
 pack .vpane.lower.commarea.buttons.commit -side top -fill x
-lappend disable_on_lock {.vpane.lower.commarea.buttons.commit conf -state}
+lappend disable_on_lock \
+       {.vpane.lower.commarea.buttons.commit conf -state}
 
 # -- Commit Message Buffer
 frame .vpane.lower.commarea.buffer
@@ -1770,7 +1773,8 @@ text $ui_comm -background white -borderwidth 1 \
        -font $font_diff \
        -yscrollcommand {.vpane.lower.commarea.buffer.sby set} \
        -cursor $maincursor
-scrollbar .vpane.lower.commarea.buffer.sby -command [list $ui_comm yview]
+scrollbar .vpane.lower.commarea.buffer.sby \
+       -command [list $ui_comm yview]
 pack $ui_coml -side top -fill x
 pack .vpane.lower.commarea.buffer.sby -side right -fill y
 pack $ui_comm -side left -fill y
@@ -1841,9 +1845,15 @@ pack .status -anchor w -side bottom -fill x
 
 # -- Load geometry
 catch {
-wm geometry . [lindex $repo_config(gui.geometry) 0 0]
-eval .vpane sash place 0 [lindex $repo_config(gui.geometry) 0 1]
-eval .vpane.files sash place 0 [lindex $repo_config(gui.geometry) 0 2]
+set gm [lindex $repo_config(gui.geometry) 0]
+wm geometry . [lindex $gm 0]
+.vpane sash place 0 \
+       [lindex [.vpane sash coord 0] 0] \
+       [lindex $gm 1]
+.vpane.files sash place 0 \
+       [lindex $gm 2] \
+       [lindex [.vpane.files sash coord 0] 1]
+unset gm
 }
 
 # -- Key Bindings