Code

git-gui: Handle starting on mapped shares under Cygwin
[git.git] / git-gui.sh
index 2686c1b8f0f176bc2888d4bb75900d3475bffb01..62e165227633338cdc8deaede8cfd07ea6ddd804 100755 (executable)
@@ -42,6 +42,8 @@ if {[catch {package require Tcl 8.4} err]
        exit 1
 }
 
+catch {rename send {}} ; # What an evil concept...
+
 ######################################################################
 ##
 ## enable verbose loading?
@@ -62,51 +64,15 @@ if {![catch {set _verbose $env(GITGUI_VERBOSE)}]} {
 
 ######################################################################
 ##
-## configure our library
-
-set oguilib {@@GITGUI_LIBDIR@@}
-set oguirel {@@GITGUI_RELATIVE@@}
-if {$oguirel eq {1}} {
-       set oguilib [file dirname [file dirname [file normalize $argv0]]]
-       set oguilib [file join $oguilib share git-gui lib]
-} elseif {[string match @@* $oguirel]} {
-       set oguilib [file join [file dirname [file normalize $argv0]] lib]
-}
-
-set idx [file join $oguilib tclIndex]
-if {[catch {set fd [open $idx r]} err]} {
-       catch {wm withdraw .}
-       tk_messageBox \
-               -icon error \
-               -type ok \
-               -title "git-gui: fatal error" \
-               -message $err
-       exit 1
-}
-if {[gets $fd] eq {# Autogenerated by git-gui Makefile}} {
-       set idx [list]
-       while {[gets $fd n] >= 0} {
-               if {$n ne {} && ![string match #* $n]} {
-                       lappend idx $n
-               }
-       }
-} else {
-       set idx {}
-}
-close $fd
+## Fake internationalization to ease backporting of changes.
 
-if {$idx ne {}} {
-       set loaded [list]
-       foreach p $idx {
-               if {[lsearch -exact $loaded $p] >= 0} continue
-               source [file join $oguilib $p]
-               lappend loaded $p
+proc mc {fmt args} {
+       set cmk [string first @@ $fmt]
+       if {$cmk > 0} {
+               set fmt [string range $fmt 0 [expr {$cmk - 1}]]
        }
-       unset loaded p
-} else {
-       set auto_path [concat [list $oguilib] $auto_path]
+       return [eval [list format $fmt] $args]
 }
-unset -nocomplain oguirel idx fd
 
 ######################################################################
 ##
@@ -309,7 +275,7 @@ proc _git_cmd {name} {
                        set s [gets $f]
                        close $f
 
-                       switch -glob -- $s {
+                       switch -glob -- [lindex $s 0] {
                        #!*sh     { set i sh     }
                        #!*perl   { set i perl   }
                        #!*python { set i python }
@@ -323,7 +289,7 @@ proc _git_cmd {name} {
                        if {$interp eq {}} {
                                error "git-$name requires $i (not in PATH)"
                        }
-                       set v [list $interp $p]
+                       set v [concat [list $interp] [lrange $s 1 end] [list $p]]
                } else {
                        # Assume it is builtin to git somehow and we
                        # aren't actually able to see a file for it.
@@ -339,7 +305,7 @@ proc _which {what} {
        global env _search_exe _search_path
 
        if {$_search_path eq {}} {
-               if {[is_Cygwin]} {
+               if {[is_Cygwin] && [regexp {^(/|\.:)} $env(PATH)]} {
                        set _search_path [split [exec cygpath \
                                --windows \
                                --path \
@@ -515,6 +481,16 @@ proc tk_optionMenu {w varName args} {
        return $m
 }
 
+proc rmsel_tag {text} {
+       $text tag conf sel \
+               -background [$text cget -background] \
+               -foreground [$text cget -foreground] \
+               -borderwidth 0
+       $text tag conf in_sel -background lightgray
+       bind $text <Motion> break
+       return $text
+}
+
 ######################################################################
 ##
 ## find git
@@ -522,7 +498,11 @@ proc tk_optionMenu {w varName args} {
 set _git  [_which git]
 if {$_git eq {}} {
        catch {wm withdraw .}
-       error_popup "Cannot find git in PATH."
+       tk_messageBox \
+               -icon error \
+               -type ok \
+               -title [mc "git-gui: fatal error"] \
+               -message [mc "Cannot find git in PATH."]
        exit 1
 }
 
@@ -532,7 +512,11 @@ if {$_git eq {}} {
 
 if {[catch {set _git_version [git --version]} err]} {
        catch {wm withdraw .}
-       error_popup "Cannot determine Git version:
+       tk_messageBox \
+               -icon error \
+               -type ok \
+               -title "git-gui: fatal error" \
+               -message "Cannot determine Git version:
 
 $err
 
@@ -541,7 +525,11 @@ $err
 }
 if {![regsub {^git version } $_git_version {} _git_version]} {
        catch {wm withdraw .}
-       error_popup "Cannot parse Git version string:\n\n$_git_version"
+       tk_messageBox \
+               -icon error \
+               -type ok \
+               -title "git-gui: fatal error" \
+               -message "Cannot parse Git version string:\n\n$_git_version"
        exit 1
 }
 
@@ -619,7 +607,11 @@ proc git-version {args} {
 
 if {[git-version < 1.5]} {
        catch {wm withdraw .}
-       error_popup "[appname] requires Git 1.5.0 or later.
+       tk_messageBox \
+               -icon error \
+               -type ok \
+               -title "git-gui: fatal error" \
+               -message "[appname] requires Git 1.5.0 or later.
 
 You are using [git-version]:
 
@@ -627,6 +619,54 @@ You are using [git-version]:
        exit 1
 }
 
+######################################################################
+##
+## configure our library
+
+set oguilib {@@GITGUI_LIBDIR@@}
+set oguirel {@@GITGUI_RELATIVE@@}
+if {$oguirel eq {1}} {
+       set oguilib [file dirname [file dirname [file normalize $argv0]]]
+       set oguilib [file join $oguilib share git-gui lib]
+} elseif {[string match @@* $oguirel]} {
+       set oguilib [file join [file dirname [file normalize $argv0]] lib]
+}
+
+set idx [file join $oguilib tclIndex]
+if {[catch {set fd [open $idx r]} err]} {
+       catch {wm withdraw .}
+       tk_messageBox \
+               -icon error \
+               -type ok \
+               -title "git-gui: fatal error" \
+               -message $err
+       exit 1
+}
+if {[gets $fd] eq {# Autogenerated by git-gui Makefile}} {
+       set idx [list]
+       while {[gets $fd n] >= 0} {
+               if {$n ne {} && ![string match #* $n]} {
+                       lappend idx $n
+               }
+       }
+} else {
+       set idx {}
+}
+close $fd
+
+if {$idx ne {}} {
+       set loaded [list]
+       foreach p $idx {
+               if {[lsearch -exact $loaded $p] >= 0} continue
+               source [file join $oguilib $p]
+               lappend loaded $p
+       }
+       unset loaded p
+} else {
+       set auto_path [concat [list $oguilib] $auto_path]
+}
+unset -nocomplain oguirel idx fd
+
 ######################################################################
 ##
 ## feature option selection
@@ -691,7 +731,15 @@ if {![file isdirectory $_gitdir]} {
        error_popup "Git directory not found:\n\n$_gitdir"
        exit 1
 }
-if {![is_enabled bare]} {
+if {$_prefix ne {}} {
+       regsub -all {[^/]+/} $_prefix ../ cdup
+       if {[catch {cd $cdup} err]} {
+               catch {wm withdraw .}
+               error_popup "Cannot move to top of working directory:\n\n$err"
+               exit 1
+       }
+       unset cdup
+} elseif {![is_enabled bare]} {
        if {[lindex [file split $_gitdir] end] ne {.git}} {
                catch {wm withdraw .}
                error_popup "Cannot use funny .git directory:\n\n$_gitdir"
@@ -726,6 +774,7 @@ set empty_tree {}
 set current_branch {}
 set is_detached 0
 set current_diff_path {}
+set is_3way_diff 0
 set selected_commit_type new
 
 ######################################################################
@@ -987,7 +1036,11 @@ proc read_ls_others {fd after} {
        set pck [split $buf_rlo "\0"]
        set buf_rlo [lindex $pck end]
        foreach p [lrange $pck 0 end-1] {
-               merge_state [encoding convertfrom $p] ?O
+               set p [encoding convertfrom $p]
+               if {[string index $p end] eq {/}} {
+                       set p [string range $p 0 end-1]
+               }
+               merge_state $p ?O
        }
        rescan_done $fd buf_rlo $after
 }
@@ -1599,7 +1652,7 @@ proc apply_config {} {
                set font [lindex $option 1]
                if {[catch {
                        foreach {cn cv} $repo_config(gui.$name) {
-                               font configure $font $cn $cv
+                               font configure $font $cn $cv -weight normal
                        }
                        } err]} {
                        error_popup "Invalid font specified in gui.$name:\n\n$err"
@@ -2112,8 +2165,8 @@ pack $ui_workdir -side left -fill both -expand 1
 .vpane.files add .vpane.files.workdir -sticky nsew
 
 foreach i [list $ui_index $ui_workdir] {
-       $i tag conf in_diff -background lightgray
-       $i tag conf in_sel  -background lightgray
+       rmsel_tag $i
+       $i tag conf in_diff -background [$i tag cget in_sel -background]
 }
 unset i
 
@@ -2416,23 +2469,23 @@ $ctxm add separator
 $ctxm add command -label {Options...} \
        -command do_options
 proc popup_diff_menu {ctxm x y X Y} {
-       global current_diff_path
+       global current_diff_path file_states
        set ::cursorX $x
        set ::cursorY $y
        if {$::ui_index eq $::current_diff_side} {
-               $ctxm entryconf $::ui_diff_applyhunk \
-                       -state normal \
-                       -label {Unstage Hunk From Commit}
-       } elseif {![info exists file_states($current_diff_path)]
-               || {_O} eq [lindex $file_states($::current_diff_path) 0]} {
-               $ctxm entryconf $::ui_diff_applyhunk \
-                       -state disabled \
-                       -label {Stage Hunk For Commit}
+               set l "Unstage Hunk From Commit"
+       } else {
+               set l "Stage Hunk For Commit"
+       }
+       if {$::is_3way_diff
+               || $current_diff_path eq {}
+               || ![info exists file_states($current_diff_path)]
+               || {_O} eq [lindex $file_states($current_diff_path) 0]} {
+               set s disabled
        } else {
-               $ctxm entryconf $::ui_diff_applyhunk \
-                       -state normal \
-                       -label {Stage Hunk For Commit}
+               set s normal
        }
+       $ctxm entryconf $::ui_diff_applyhunk -state $s -label $l
        tk_popup $ctxm $X $Y
 }
 bind_button3 $ui_diff [list popup_diff_menu $ctxm %x %y %X %Y]