git-gui: make _shellpath usable on startup

Since commit d5257fb3c1de (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 <mlevedahl@gmail.com> Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Taylor Blau <me@ttaylorr.com>

Mark Levedahl committed Apr 1, 2025 at 11:45 UTC 10637fc327fe9d3afd19a11ed64bd9e1c7a9c6b5
1 file changed +30 -8
git-gui.sh
+30 -8
@@ -307,15 +307,37 @@ if {$_trace >= 0} {
307 # branches).
308 set _last_merged_branch {}
309
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
316 }
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
341 return $_shellpath
342 }
343