Skip to content

Commit e7b6f63

Browse files
committed
Merge branch 'gitk-and-git-gui-patches'
These are Git for Windows' Git GUI and gitk patches. We will have to decide at some point what to do about them, but that's a little lower priority (as Git GUI seems to be unmaintained for the time being, and the gitk maintainer keeps a very low profile on the Git mailing list, too). Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 941090e + 48bc03a commit e7b6f63

File tree

4 files changed

+160
-57
lines changed

4 files changed

+160
-57
lines changed

git-gui/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ install: all
293293
$(QUIET)$(INSTALL_D0)'$(DESTDIR_SQ)$(gitexecdir_SQ)' $(INSTALL_D1)
294294
$(QUIET)$(INSTALL_X0)git-gui $(INSTALL_X1) '$(DESTDIR_SQ)$(gitexecdir_SQ)'
295295
$(QUIET)$(INSTALL_X0)git-gui--askpass $(INSTALL_X1) '$(DESTDIR_SQ)$(gitexecdir_SQ)'
296+
$(QUIET)$(INSTALL_X0)git-gui--askyesno $(INSTALL_X1) '$(DESTDIR_SQ)$(gitexecdir_SQ)'
296297
$(QUIET)$(foreach p,$(GITGUI_BUILT_INS), $(INSTALL_L0)'$(DESTDIR_SQ)$(gitexecdir_SQ)/$p' $(INSTALL_L1)'$(DESTDIR_SQ)$(gitexecdir_SQ)/git-gui' $(INSTALL_L2)'$(DESTDIR_SQ)$(gitexecdir_SQ)/$p' $(INSTALL_L3) &&) true
297298
ifdef GITGUI_WINDOWS_WRAPPER
298299
$(QUIET)$(INSTALL_R0)git-gui.tcl $(INSTALL_R1) '$(DESTDIR_SQ)$(gitexecdir_SQ)'
@@ -311,6 +312,7 @@ uninstall:
311312
$(QUIET)$(CLEAN_DST) '$(DESTDIR_SQ)$(gitexecdir_SQ)'
312313
$(QUIET)$(REMOVE_F0)'$(DESTDIR_SQ)$(gitexecdir_SQ)'/git-gui $(REMOVE_F1)
313314
$(QUIET)$(REMOVE_F0)'$(DESTDIR_SQ)$(gitexecdir_SQ)'/git-gui--askpass $(REMOVE_F1)
315+
$(QUIET)$(REMOVE_F0)'$(DESTDIR_SQ)$(gitexecdir_SQ)'/git-gui--askyesno $(REMOVE_F1)
314316
$(QUIET)$(foreach p,$(GITGUI_BUILT_INS), $(REMOVE_F0)'$(DESTDIR_SQ)$(gitexecdir_SQ)'/$p $(REMOVE_F1) &&) true
315317
ifdef GITGUI_WINDOWS_WRAPPER
316318
$(QUIET)$(REMOVE_F0)'$(DESTDIR_SQ)$(gitexecdir_SQ)'/git-gui.tcl $(REMOVE_F1)

git-gui/git-gui--askyesno

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/sh
2+
# Tcl ignores the next line -*- tcl -*- \
3+
exec wish "$0" -- "$@"
4+
5+
# This is an implementation of a simple yes no dialog
6+
# which is injected into the git commandline by git gui
7+
# in case a yesno question needs to be answered.
8+
9+
set NS {}
10+
set use_ttk [package vsatisfies [package provide Tk] 8.5]
11+
if {$use_ttk} {
12+
set NS ttk
13+
}
14+
15+
set title "Question?"
16+
if {$argc < 1} {
17+
puts stderr "Usage: $argv0 <question>"
18+
exit 1
19+
} else {
20+
if {$argc > 2 && [lindex $argv 0] == "--title"} {
21+
set title [lindex $argv 1]
22+
set argv [lreplace $argv 0 1]
23+
}
24+
set prompt [join $argv " "]
25+
}
26+
27+
${NS}::frame .t
28+
${NS}::label .t.m -text $prompt -justify center -width 400px
29+
.t.m configure -wraplength 400px
30+
pack .t.m -side top -fill x -padx 20 -pady 20 -expand 1
31+
pack .t -side top -fill x -ipadx 20 -ipady 20 -expand 1
32+
33+
${NS}::frame .b
34+
${NS}::frame .b.left -width 200
35+
${NS}::button .b.yes -text Yes -command yes
36+
${NS}::button .b.no -text No -command no
37+
38+
39+
pack .b.left -side left -expand 1 -fill x
40+
pack .b.yes -side left -expand 1
41+
pack .b.no -side right -expand 1 -ipadx 5
42+
pack .b -side bottom -fill x -ipadx 20 -ipady 15
43+
44+
bind . <Key-Return> {exit 0}
45+
bind . <Key-Escape> {exit 1}
46+
47+
proc no {} {
48+
exit 1
49+
}
50+
51+
proc yes {} {
52+
exit 0
53+
}
54+
55+
if {$::tcl_platform(platform) eq {windows}} {
56+
set icopath [file dirname [file normalize $argv0]]
57+
if {[file tail $icopath] eq {git-core}} {
58+
set icopath [file dirname $icopath]
59+
}
60+
set icopath [file dirname $icopath]
61+
set icopath [file join $icopath share git git-for-windows.ico]
62+
if {[file exists $icopath]} {
63+
wm iconbitmap . -default $icopath
64+
}
65+
}
66+
67+
wm title . $title
68+
tk::PlaceWindow .

git-gui/git-gui.sh

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,11 @@ proc git_write {args} {
623623
}
624624
625625
proc githook_read {hook_name args} {
626-
set pchook [gitdir hooks $hook_name]
626+
if {[package vcompare $::_git_version 2.5.0] >= 0} {
627+
set pchook [git rev-parse --git-path "hooks/$hook_name"]
628+
} else {
629+
set pchook [gitdir hooks $hook_name]
630+
}
627631
lappend args 2>@1
628632
629633
# On Windows [file executable] might lie so we need to ask
@@ -1229,6 +1233,12 @@ set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}]
12291233
if {![info exists env(SSH_ASKPASS)]} {
12301234
set env(SSH_ASKPASS) [gitexec git-gui--askpass]
12311235
}
1236+
if {![info exists env(GIT_ASKPASS)]} {
1237+
set env(GIT_ASKPASS) [gitexec git-gui--askpass]
1238+
}
1239+
if {![info exists env(GIT_ASK_YESNO)]} {
1240+
set env(GIT_ASK_YESNO) [gitexec git-gui--askyesno]
1241+
}
12321242
12331243
######################################################################
12341244
##
@@ -1325,9 +1335,6 @@ if {[lindex $_reponame end] eq {.git}} {
13251335
set _reponame [lindex $_reponame end]
13261336
}
13271337
1328-
set env(GIT_DIR) $_gitdir
1329-
set env(GIT_WORK_TREE) $_gitworktree
1330-
13311338
######################################################################
13321339
##
13331340
## global init
@@ -2152,7 +2159,7 @@ set starting_gitk_msg [mc "Starting gitk... please wait..."]
21522159
21532160
proc do_gitk {revs {is_submodule false}} {
21542161
global current_diff_path file_states current_diff_side ui_index
2155-
global _gitdir _gitworktree
2162+
global _gitworktree
21562163
21572164
# -- Always start gitk through whatever we were loaded with. This
21582165
# lets us bypass using shell process on Windows systems.
@@ -2164,12 +2171,19 @@ proc do_gitk {revs {is_submodule false}} {
21642171
} else {
21652172
global env
21662173
2174+
if {[info exists env(GIT_DIR)]} {
2175+
set old_GIT_DIR $env(GIT_DIR)
2176+
} else {
2177+
set old_GIT_DIR {}
2178+
}
2179+
21672180
set pwd [pwd]
21682181
21692182
if {!$is_submodule} {
21702183
if {![is_bare]} {
21712184
cd $_gitworktree
21722185
}
2186+
set env(GIT_DIR) [file normalize [gitdir]]
21732187
} else {
21742188
cd $current_diff_path
21752189
if {$revs eq {--}} {
@@ -2190,18 +2204,17 @@ proc do_gitk {revs {is_submodule false}} {
21902204
}
21912205
set revs $old_sha1...$new_sha1
21922206
}
2193-
# GIT_DIR and GIT_WORK_TREE for the submodule are not the ones
2194-
# we've been using for the main repository, so unset them.
2195-
# TODO we could make life easier (start up faster?) for gitk
2196-
# by setting these to the appropriate values to allow gitk
2197-
# to skip the heuristics to find their proper value
2198-
unset env(GIT_DIR)
2199-
unset env(GIT_WORK_TREE)
2207+
if {[info exists env(GIT_DIR)]} {
2208+
unset env(GIT_DIR)
2209+
}
22002210
}
22012211
eval exec $cmd $revs "--" "--" &
22022212
2203-
set env(GIT_DIR) $_gitdir
2204-
set env(GIT_WORK_TREE) $_gitworktree
2213+
if {$old_GIT_DIR ne {}} {
2214+
set env(GIT_DIR) $old_GIT_DIR
2215+
} else {
2216+
unset env(GIT_DIR)
2217+
}
22052218
cd $pwd
22062219
22072220
ui_status $::starting_gitk_msg
@@ -2222,20 +2235,22 @@ proc do_git_gui {} {
22222235
error_popup [mc "Couldn't find git gui in PATH"]
22232236
} else {
22242237
global env
2225-
global _gitdir _gitworktree
22262238
2227-
# see note in do_gitk about unsetting these vars when
2228-
# running tools in a submodule
2229-
unset env(GIT_DIR)
2230-
unset env(GIT_WORK_TREE)
2239+
if {[info exists env(GIT_DIR)]} {
2240+
set old_GIT_DIR $env(GIT_DIR)
2241+
unset env(GIT_DIR)
2242+
} else {
2243+
set old_GIT_DIR {}
2244+
}
22312245
22322246
set pwd [pwd]
22332247
cd $current_diff_path
22342248
22352249
eval exec $exe gui &
22362250
2237-
set env(GIT_DIR) $_gitdir
2238-
set env(GIT_WORK_TREE) $_gitworktree
2251+
if {$old_GIT_DIR ne {}} {
2252+
set env(GIT_DIR) $old_GIT_DIR
2253+
}
22392254
cd $pwd
22402255
22412256
ui_status $::starting_gitk_msg
@@ -2706,10 +2721,18 @@ if {![is_bare]} {
27062721
}
27072722
27082723
if {[is_Windows]} {
2724+
# Use /git-bash.exe if available
2725+
set normalized [file normalize $::argv0]
2726+
regsub "/mingw../libexec/git-core/git-gui$" \
2727+
$normalized "/git-bash.exe" cmdLine
2728+
if {$cmdLine != $normalized && [file exists $cmdLine]} {
2729+
set cmdLine [list "Git Bash" $cmdLine &]
2730+
} else {
2731+
set cmdLine [list "Git Bash" bash --login -l &]
2732+
}
27092733
.mbar.repository add command \
27102734
-label [mc "Git Bash"] \
2711-
-command {eval exec [auto_execok start] \
2712-
[list "Git Bash" bash --login -l &]}
2735+
-command {eval exec [auto_execok start] $cmdLine}
27132736
}
27142737
27152738
if {[is_Windows] || ![is_bare]} {

0 commit comments

Comments
 (0)