Merge branch 'maint' of git://repo.or.cz/git-gui into maint

* 'maint' of git://repo.or.cz/git-gui:
  git-gui: Focus insertion point at end of strings in repository chooser
  git-gui: Avoid hardcoded Windows paths in Cygwin package files
  git-gui: Default TCL_PATH to same location as TCLTK_PATH
  git-gui: Paper bag fix error dialogs opening over the main window
  git-gui: Ensure error dialogs always appear over all other windows
  git-gui: relax "dirty" version detection
  git-gui: support Git Gui.app under OS X 10.5
diff --git a/git-gui/Makefile b/git-gui/Makefile
index 34438cd..01e0a46 100644
--- a/git-gui/Makefile
+++ b/git-gui/Makefile
@@ -13,6 +13,7 @@
 
 uname_S := $(shell sh -c 'uname -s 2>/dev/null || echo not')
 uname_O := $(shell sh -c 'uname -o 2>/dev/null || echo not')
+uname_R := $(shell sh -c 'uname -r 2>/dev/null || echo not')
 
 SCRIPT_SH = git-gui.sh
 GITGUI_MAIN := git-gui
@@ -91,9 +92,20 @@
 	REMOVE_F1 = && echo '   ' REMOVE `basename "$$dst"` && $(RM_RF) "$$dst"
 endif
 
-TCL_PATH   ?= tclsh
 TCLTK_PATH ?= wish
-TKFRAMEWORK = /Library/Frameworks/Tk.framework/Resources/Wish.app
+ifeq (./,$(dir $(TCLTK_PATH)))
+	TCL_PATH ?= $(subst wish,tclsh,$(TCLTK_PATH))
+else
+	TCL_PATH ?= $(dir $(TCLTK_PATH))$(notdir $(subst wish,tclsh,$(TCLTK_PATH)))
+endif
+
+ifeq ($(uname_S),Darwin)
+	TKFRAMEWORK = /Library/Frameworks/Tk.framework/Resources/Wish.app
+	ifeq ($(shell expr "$(uname_R)" : '9\.'),2)
+		TKFRAMEWORK = /System/Library/Frameworks/Tk.framework/Resources/Wish\ Shell.app
+	endif
+	TKEXECUTABLE = $(shell basename "$(TKFRAMEWORK)" .app)
+endif
 
 ifeq ($(findstring $(MAKEFLAGS),s),s)
 QUIET_GEN =
@@ -119,7 +131,17 @@
 
 ifeq ($(uname_O),Cygwin)
 	GITGUI_SCRIPT := `cygpath --windows --absolute "$(GITGUI_SCRIPT)"`
-	gg_libdir_sed_in := $(shell cygpath --windows --absolute "$(gg_libdir)")
+
+	# Is this a Cygwin Tcl/Tk binary?  If so it knows how to do
+	# POSIX path translation just like cygpath does and we must
+	# keep libdir in POSIX format so Cygwin packages of git-gui
+	# work no matter where the user installs them.
+	#
+	ifeq ($(shell echo 'puts [file normalize /]' | '$(TCL_PATH_SQ)'),$(shell cygpath --mixed --absolute /))
+		gg_libdir_sed_in := $(gg_libdir)
+	else
+		gg_libdir_sed_in := $(shell cygpath --windows --absolute "$(gg_libdir)")
+	endif
 else
 	ifeq ($(exedir),$(gg_libdir))
 		GITGUI_RELATIVE := 1
@@ -147,7 +169,7 @@
 	echo then >>$@+ && \
 	echo '	'echo \'git-gui version '$(GITGUI_VERSION)'\' >>$@+ && \
 	echo else >>$@+ && \
-	echo '	'exec \''$(libdir_SQ)/Git Gui.app/Contents/MacOS/Wish'\' \
+	echo '	'exec \''$(libdir_SQ)/Git Gui.app/Contents/MacOS/$(subst \,,$(TKEXECUTABLE))'\' \
 		'"$$0" "$$@"' >>$@+ && \
 	echo fi >>$@+ && \
 	chmod +x $@+ && \
@@ -157,14 +179,15 @@
 		macosx/Info.plist \
 		macosx/git-gui.icns \
 		macosx/AppMain.tcl \
-		$(TKFRAMEWORK)/Contents/MacOS/Wish
+		$(TKFRAMEWORK)/Contents/MacOS/$(TKEXECUTABLE)
 	$(QUIET_GEN)rm -rf '$@' '$@'+ && \
 	mkdir -p '$@'+/Contents/MacOS && \
 	mkdir -p '$@'+/Contents/Resources/Scripts && \
-	cp '$(subst ','\'',$(TKFRAMEWORK))/Contents/MacOS/Wish' \
+	cp '$(subst ','\'',$(subst \,,$(TKFRAMEWORK)/Contents/MacOS/$(TKEXECUTABLE)))' \
 		'$@'+/Contents/MacOS && \
 	cp macosx/git-gui.icns '$@'+/Contents/Resources && \
 	sed -e 's/@@GITGUI_VERSION@@/$(GITGUI_VERSION)/g' \
+		-e 's/@@GITGUI_TKEXECUTABLE@@/$(TKEXECUTABLE)/g' \
 		macosx/Info.plist \
 		>'$@'+/Contents/Info.plist && \
 	sed -e 's|@@gitexecdir@@|$(gitexecdir_SQ)|' \
diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh
index f42e461..04bd425 100755
--- a/git-gui/git-gui.sh
+++ b/git-gui/git-gui.sh
@@ -662,7 +662,7 @@
 }
 
 set _real_git_version $_git_version
-regsub -- {-dirty$} $_git_version {} _git_version
+regsub -- {[\-\.]dirty$} $_git_version {} _git_version
 regsub {\.[0-9]+\.g[0-9a-f]+$} $_git_version {} _git_version
 regsub {\.rc[0-9]+$} $_git_version {} _git_version
 regsub {\.GIT$} $_git_version {} _git_version
diff --git a/git-gui/lib/choose_repository.tcl b/git-gui/lib/choose_repository.tcl
index 86faf24..0adcf9d 100644
--- a/git-gui/lib/choose_repository.tcl
+++ b/git-gui/lib/choose_repository.tcl
@@ -11,6 +11,7 @@
 field o_cons      ; # Console object (if active)
 field w_types     ; # List of type buttons in clone
 field w_recentlist ; # Listbox containing recent repositories
+field w_localpath  ; # Entry widget bound to local_path
 
 field done              0 ; # Finished picking the repository?
 field local_path       {} ; # Where this repository is locally
@@ -385,6 +386,7 @@
 	button $w_body.where.b \
 		-text [mc "Browse"] \
 		-command [cb _new_local_path]
+	set w_localpath $w_body.where.t
 
 	pack $w_body.where.b -side right
 	pack $w_body.where.l -side left
@@ -416,6 +418,7 @@
 		return
 	}
 	set local_path $p
+	$w_localpath icursor end
 }
 
 method _do_new2 {} {
@@ -481,6 +484,7 @@
 		-text [mc "Browse"] \
 		-command [cb _new_local_path]
 	grid $args.where_l $args.where_t $args.where_b -sticky ew
+	set w_localpath $args.where_t
 
 	label $args.type_l -text [mc "Clone Type:"]
 	frame $args.type_f
diff --git a/git-gui/lib/error.tcl b/git-gui/lib/error.tcl
index 0fdd753..08a2462 100644
--- a/git-gui/lib/error.tcl
+++ b/git-gui/lib/error.tcl
@@ -1,6 +1,14 @@
 # git-gui branch (create/delete) support
 # Copyright (C) 2006, 2007 Shawn Pearce
 
+proc _error_parent {} {
+	set p [grab current .]
+	if {$p eq {}} {
+		return .
+	}
+	return $p
+}
+
 proc error_popup {msg} {
 	set title [appname]
 	if {[reponame] ne {}} {
@@ -11,8 +19,8 @@
 		-type ok \
 		-title [append "$title: " [mc "error"]] \
 		-message $msg]
-	if {[winfo ismapped .]} {
-		lappend cmd -parent .
+	if {[winfo ismapped [_error_parent]]} {
+		lappend cmd -parent [_error_parent]
 	}
 	eval $cmd
 }
@@ -27,13 +35,13 @@
 		-type ok \
 		-title [append "$title: " [mc "warning"]] \
 		-message $msg]
-	if {[winfo ismapped .]} {
-		lappend cmd -parent .
+	if {[winfo ismapped [_error_parent]]} {
+		lappend cmd -parent [_error_parent]
 	}
 	eval $cmd
 }
 
-proc info_popup {msg {parent .}} {
+proc info_popup {msg} {
 	set title [appname]
 	if {[reponame] ne {}} {
 		append title " ([reponame])"
@@ -56,8 +64,8 @@
 		-type yesno \
 		-title $title \
 		-message $msg]
-	if {[winfo ismapped .]} {
-		lappend cmd -parent .
+	if {[winfo ismapped [_error_parent]]} {
+		lappend cmd -parent [_error_parent]
 	}
 	eval $cmd
 }
diff --git a/git-gui/macosx/Info.plist b/git-gui/macosx/Info.plist
index 99913ec..b3bf15f 100644
--- a/git-gui/macosx/Info.plist
+++ b/git-gui/macosx/Info.plist
@@ -5,7 +5,7 @@
 	<key>CFBundleDevelopmentRegion</key>
 	<string>English</string>
 	<key>CFBundleExecutable</key>
-	<string>Wish</string>
+	<string>@@GITGUI_TKEXECUTABLE@@</string>
 	<key>CFBundleGetInfoString</key>
 	<string>Git Gui @@GITGUI_VERSION@@ © 2006-2007 Shawn Pearce, et. al.</string>
 	<key>CFBundleIconFile</key>