Skip to content

Commit 10637fc

Browse files
mark987ttaylorr
authored andcommitted
git-gui: make _shellpath usable on startup
Since commit d5257fb (git-gui: handle textconv filter on Windows and in development, 2010-08-07), git-gui will search for a usable shell if _shellpath is not configured, and on Windows may resort to using auto_execok to find 'sh'. While this was intended for development use, checks are insufficient to assure a proper configuration when deployed where _shellpath is always set, but might not give a usable shell. Let's make this more robust by only searching if _shellpath was not defined, and then using only our restricted search functions. Furthermore, we should convert to a Windows path on Windows. Always check for a valid shell on startup, meaning an absolute path to an executable, aborting if these conditions are not met. Signed-off-by: Mark Levedahl <[email protected]> Signed-off-by: Johannes Sixt <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent c5c3278 commit 10637fc

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

git-gui.sh

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -307,15 +307,37 @@ if {$_trace >= 0} {
307307
# branches).
308308
set _last_merged_branch {}
309309
310-
proc shellpath {} {
311-
global _shellpath env
312-
if {[string match @@* $_shellpath]} {
313-
if {[info exists env(SHELL)]} {
314-
return $env(SHELL)
315-
} else {
316-
return /bin/sh
317-
}
310+
# for testing, allow unconfigured _shellpath
311+
if {[string match @@* $_shellpath]} {
312+
if {[info exists env(SHELL)]} {
313+
set _shellpath $env(SHELL)
314+
} else {
315+
set _shellpath /bin/sh
318316
}
317+
}
318+
319+
if {[is_Windows]} {
320+
set _shellpath [exec cygpath -m $_shellpath]
321+
}
322+
323+
if {![file executable $_shellpath] || \
324+
!([file pathtype $_shellpath] eq {absolute})} {
325+
set errmsg "The defined shell ('$_shellpath') is not usable, \
326+
it must be an absolute path to an executable."
327+
puts stderr $errmsg
328+
329+
catch {wm withdraw .}
330+
tk_messageBox \
331+
-icon error \
332+
-type ok \
333+
-title "git-gui: configuration error" \
334+
-message $errmsg
335+
exit 1
336+
}
337+
338+
339+
proc shellpath {} {
340+
global _shellpath
319341
return $_shellpath
320342
}
321343

0 commit comments

Comments
 (0)