Skip to content

Commit 412b9a1

Browse files
dschogitster
authored andcommitted
t2300: "git --exec-path" is not usable in $PATH on Windows as-is
The "git" command prepends the exec-path to the PATH environment variable for processes it spawns. That is how ". git-sh-setup" in our scripted Porcelains can find the dot-sourced file in the exec-path location that is not usually on user's PATH. When t2300 runs, because it is not spawned by the "git" command, the scriptlet being tested did not run with a realistic setting of PATH environment. It lacked the exec-path on the PATH, and failed to find the dot-sourced file. A recent update to t2300 attempted to fix this, with "PATH=$(git --exec-path):$PATH", which has been the recommended way around v1.6.0 days (a script whose original was written before that release that survives to this day is likely to have such a line). However, the "git --exec-path" command outputs C:\path\to\exec\dir (not /c/path/to/exec/dir) on Windows; the recent update failed to consider the problem that comes from it. Even though Git itself, when doing the equivalent internally, does so in a platform native way (i.e. on Windows, C:\path\to\exec\dir is prepended to the existing value of %PATH% using ';' as a component separator), the result is further massaged by bash and gets turned into $PATH that uses /c/path/to/exec/dir with ':' separating the components, which is the form understood by bash, so scripted Porcelains find commands from PATH correctly. An end user script written in shell, however, cannot prepend "C:\path\to\exec\dir:" to the existing value of $PATH and expect bash to magically turn it into the form it understands. In other words, "PATH=$(git --exec-path):$PATH" does not work as an emulation of what "Git" internally does to the PATH on Windows. To correctly emulate how exec-path is prepended to the PATH environment internally on Windows, we'd need to convert C:\git-sdk-64\usr\src\git to at least /c\git-sdk-64\usr\src\git ourselves before prepending it to PATH. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fe17fc0 commit 412b9a1

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

t/t2300-cd-to-toplevel.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@ test_description='cd_to_toplevel'
44

55
. ./test-lib.sh
66

7+
EXEC_PATH="$(git --exec-path)"
8+
test_have_prereq !MINGW ||
9+
case "$EXEC_PATH" in
10+
[A-Za-z]:/*)
11+
EXEC_PATH="/${EXEC_PATH%%:*}${EXEC_PATH#?:}"
12+
;;
13+
esac
14+
715
test_cd_to_toplevel () {
816
test_expect_success $3 "$2" '
917
(
1018
cd '"'$1'"' &&
11-
PATH="$(git --exec-path):$PATH" &&
19+
PATH="$EXEC_PATH:$PATH" &&
1220
. git-sh-setup &&
1321
cd_to_toplevel &&
1422
[ "$(pwd -P)" = "$TOPLEVEL" ]

0 commit comments

Comments
 (0)