Skip to content

Commit 8c76212

Browse files
angavrilovspearce
authored andcommitted
git-gui: Add a simple implementation of SSH_ASKPASS.
OpenSSH allows specifying an external program to use for direct user interaction. While most Linux systems already have such programs, some environments, for instance, msysgit, lack it. This patch adds a simple fallback Tcl implementation of the tool. In msysgit it is also necessary to set a fake value of the DISPLAY variable, because otherwise ssh won't even try to use SSH_ASKPASS handlers. Signed-off-by: Alexander Gavrilov <[email protected]> Acked-by: Johannes Sixt <[email protected]> Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent 98a6846 commit 8c76212

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ all:: $(GITGUI_MAIN) lib/tclIndex $(ALL_MSGFILES)
285285
install: all
286286
$(QUIET)$(INSTALL_D0)'$(DESTDIR_SQ)$(gitexecdir_SQ)' $(INSTALL_D1)
287287
$(QUIET)$(INSTALL_X0)git-gui $(INSTALL_X1) '$(DESTDIR_SQ)$(gitexecdir_SQ)'
288+
$(QUIET)$(INSTALL_X0)git-gui--askpass $(INSTALL_X1) '$(DESTDIR_SQ)$(gitexecdir_SQ)'
288289
$(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
289290
ifdef GITGUI_WINDOWS_WRAPPER
290291
$(QUIET)$(INSTALL_R0)git-gui.tcl $(INSTALL_R1) '$(DESTDIR_SQ)$(gitexecdir_SQ)'
@@ -302,6 +303,7 @@ endif
302303
uninstall:
303304
$(QUIET)$(CLEAN_DST) '$(DESTDIR_SQ)$(gitexecdir_SQ)'
304305
$(QUIET)$(REMOVE_F0)'$(DESTDIR_SQ)$(gitexecdir_SQ)'/git-gui $(REMOVE_F1)
306+
$(QUIET)$(REMOVE_F0)'$(DESTDIR_SQ)$(gitexecdir_SQ)'/git-gui--askpass $(REMOVE_F1)
305307
$(QUIET)$(foreach p,$(GITGUI_BUILT_INS), $(REMOVE_F0)'$(DESTDIR_SQ)$(gitexecdir_SQ)'/$p $(REMOVE_F1) &&) true
306308
ifdef GITGUI_WINDOWS_WRAPPER
307309
$(QUIET)$(REMOVE_F0)'$(DESTDIR_SQ)$(gitexecdir_SQ)'/git-gui.tcl $(REMOVE_F1)

git-gui--askpass

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/sh
2+
# Tcl ignores the next line -*- tcl -*- \
3+
exec wish "$0" -- "$@"
4+
5+
# This is a trivial implementation of an SSH_ASKPASS handler.
6+
# Git-gui uses this script if none are already configured.
7+
8+
set answer {}
9+
set yesno 0
10+
set rc 255
11+
12+
if {$argc < 1} {
13+
set prompt "Enter your OpenSSH passphrase:"
14+
} else {
15+
set prompt [join $argv " "]
16+
if {[regexp -nocase {\(yes\/no\)\?\s*$} $prompt]} {
17+
set yesno 1
18+
}
19+
}
20+
21+
message .m -text $prompt -justify center -aspect 4000
22+
pack .m -side top -fill x -padx 20 -pady 20 -expand 1
23+
24+
entry .e -textvariable answer -width 50
25+
pack .e -side top -fill x -padx 10 -pady 10
26+
27+
if {!$yesno} {
28+
.e configure -show "*"
29+
}
30+
31+
frame .b
32+
button .b.ok -text OK -command finish
33+
button .b.cancel -text Cancel -command {destroy .}
34+
35+
pack .b.ok -side left -expand 1
36+
pack .b.cancel -side right -expand 1
37+
pack .b -side bottom -fill x -padx 10 -pady 10
38+
39+
bind . <Visibility> {focus -force .e}
40+
bind . <Key-Return> finish
41+
bind . <Key-Escape> {destroy .}
42+
bind . <Destroy> {exit $rc}
43+
44+
proc finish {} {
45+
if {$::yesno} {
46+
if {$::answer ne "yes" && $::answer ne "no"} {
47+
tk_messageBox -icon error -title "Error" -type ok \
48+
-message "Only 'yes' or 'no' input allowed."
49+
return
50+
}
51+
}
52+
53+
set ::rc 0
54+
puts $::answer
55+
destroy .
56+
}
57+
58+
wm title . "OpenSSH"
59+
tk::PlaceWindow .

git-gui.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,11 @@ bind . <Visibility> {
592592
if {[is_Windows]} {
593593
wm iconbitmap . -default $oguilib/git-gui.ico
594594
set ::tk::AlwaysShowSelection 1
595+
596+
# Spoof an X11 display for SSH
597+
if {![info exists env(DISPLAY)]} {
598+
set env(DISPLAY) :9999
599+
}
595600
}
596601
597602
######################################################################
@@ -1070,6 +1075,13 @@ set nullid2 "0000000000000000000000000000000000000001"
10701075
10711076
set have_tk85 [expr {[package vcompare $tk_version "8.5"] >= 0}]
10721077
1078+
######################################################################
1079+
1080+
# Suggest our implementation of askpass, if none is set
1081+
if {![info exists env(SSH_ASKPASS)]} {
1082+
set env(SSH_ASKPASS) [gitexec git-gui--askpass]
1083+
}
1084+
10731085
######################################################################
10741086
##
10751087
## task management

0 commit comments

Comments
 (0)