end]
append title {)}
}
- tk_messageBox \
- -parent . \
+ set cmd [list tk_messageBox \
-icon error \
-type ok \
-title "$title: error" \
- -message $msg
+ -message $msg]
+ if {[winfo ismapped .]} {
+ lappend cmd -parent .
+ }
+ eval $cmd
}
proc info_popup {msg} {
error_popup "Cannot find the git directory:\n\n$err"
exit 1
}
+if {![file isdirectory $gitdir]} {
+ catch {wm withdraw .}
+ error_popup "Git directory not found:\n\n$gitdir"
+ exit 1
+}
+if {[lindex [file split $gitdir] end] ne {.git}} {
+ catch {wm withdraw .}
+ error_popup "Cannot use funny .git directory:\n\n$gitdir"
+ exit 1
+}
if {[catch {cd [file dirname $gitdir]} err]} {
catch {wm withdraw .}
error_popup "No working directory [file dirname $gitdir]:\n\n$err"
set all_remotes [lsort -unique $all_remotes]
}
-proc populate_remote_menu {m pfx op} {
- global all_remotes
+proc populate_fetch_menu {m} {
+ global gitdir all_remotes repo_config
- foreach remote $all_remotes {
- $m add command -label "$pfx $remote..." \
- -command [list $op $remote] \
- -font font_ui
+ foreach r $all_remotes {
+ set enable 0
+ if {![catch {set a $repo_config(remote.$r.url)}]} {
+ if {![catch {set a $repo_config(remote.$r.fetch)}]} {
+ set enable 1
+ }
+ } else {
+ catch {
+ set fd [open [file join $gitdir remotes $r] r]
+ while {[gets $fd n] >= 0} {
+ if {[regexp {^Pull:[ \t]*([^:]+):} $n]} {
+ set enable 1
+ break
+ }
+ }
+ close $fd
+ }
+ }
+
+ if {$enable} {
+ $m add command \
+ -label "Fetch from $r..." \
+ -command [list fetch_from $r] \
+ -font font_ui
+ }
+ }
+}
+
+proc populate_push_menu {m} {
+ global gitdir all_remotes repo_config
+
+ foreach r $all_remotes {
+ set enable 0
+ if {![catch {set a $repo_config(remote.$r.url)}]} {
+ if {![catch {set a $repo_config(remote.$r.push)}]} {
+ set enable 1
+ }
+ } else {
+ catch {
+ set fd [open [file join $gitdir remotes $r] r]
+ while {[gets $fd n] >= 0} {
+ if {[regexp {^Push:[ \t]*([^:]+):} $n]} {
+ set enable 1
+ break
+ }
+ }
+ close $fd
+ }
+ }
+
+ if {$enable} {
+ $m add command \
+ -label "Push to $r..." \
+ -command [list push_to $r] \
+ -font font_ui
+ }
}
}
--unix \
--absolute \
$gitdir]
+ regsub -all ' $me "'\\''" me
+ regsub -all ' $gd "'\\''" gd
puts -nonewline $fd "\"$sh\" --login -c \""
- puts -nonewline $fd "GIT_DIR=\\\"$gd\\\""
- puts -nonewline $fd " \\\"$me\\\""
+ puts -nonewline $fd "GIT_DIR='$gd'"
+ puts -nonewline $fd " '$me'"
puts $fd "&\""
close $fd
} err]} {
}
}
+proc do_macosx_app {} {
+ global gitdir appname argv0 env
+
+ set reponame [lindex [file split \
+ [file normalize [file dirname $gitdir]]] \
+ end]
+
+ set fn [tk_getSaveFile \
+ -parent . \
+ -title "$appname ($reponame): Create Desktop Icon" \
+ -initialdir [file join $env(HOME) Desktop] \
+ -initialfile "Git $reponame.app"]
+ if {$fn != {}} {
+ if {[catch {
+ set Contents [file join $fn Contents]
+ set MacOS [file join $Contents MacOS]
+ set exe [file join $MacOS git-gui]
+
+ file mkdir $MacOS
+
+ set fd [open [file join $Contents PkgInfo] w]
+ puts -nonewline $fd {APPL????}
+ close $fd
+
+ set fd [open [file join $Contents Info.plist] w]
+ puts $fd {<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>English</string>
+ <key>CFBundleExecutable</key>
+ <string>git-gui</string>
+ <key>CFBundleIdentifier</key>
+ <string>org.spearce.git-gui</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1.0</string>
+ <key>NSPrincipalClass</key>
+ <string>NSApplication</string>
+</dict>
+</plist>}
+ close $fd
+
+ set fd [open $exe w]
+ set gd [file normalize $gitdir]
+ set ep [file normalize [exec git --exec-path]]
+ regsub -all ' $gd "'\\''" gd
+ regsub -all ' $ep "'\\''" ep
+ puts $fd "#!/bin/sh"
+ foreach name [array names env] {
+ if {[string match GIT_* $name]} {
+ regsub -all ' $env($name) "'\\''" v
+ puts $fd "export $name='$v'"
+ }
+ }
+ puts $fd "export PATH='$ep':\$PATH"
+ puts $fd "export GIT_DIR='$gd'"
+ puts $fd "exec [file normalize $argv0]"
+ close $fd
+
+ file attributes $exe -permissions u+x,g+x,o+x
+ } err]} {
+ error_popup "Cannot write icon:\n\n$err"
+ }
+ }
+}
+
proc toggle_or_diff {w x y} {
global file_lists ui_index ui_other
global last_clicked selected_paths
-label {Create Desktop Icon} \
-command do_windows_shortcut \
-font font_ui
+ } elseif {[is_MacOSX]} {
+ .mbar.project add command \
+ -label {Create Desktop Icon} \
+ -command do_macosx_app \
+ -font font_ui
}
}
.mbar.project add command -label Quit \
focus -force $ui_comm
if {!$single_commit} {
load_all_remotes
- populate_remote_menu .mbar.fetch From fetch_from
- populate_remote_menu .mbar.push To push_to
+ populate_fetch_menu .mbar.fetch
populate_pull_menu .mbar.pull
+ populate_push_menu .mbar.push
}
after 1 do_rescan