Skip to content

Commit f4f5fd7

Browse files
committed
go-template: Only use cygpath on Git for Windows
As it turns out, regular MSYS2 and Cygwin do not work with with file paths modified with `cygpath -m`. This change tries to ensure only Git for Windows is affected by checking the `EXEPATH` variable.
1 parent 2f6aeca commit f4f5fd7

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

go-template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ download_go_script_bash_tarball() {
5959
if [[ "$protocol" == "$url" ]]; then
6060
printf 'GO_SCRIPT_BASH_DOWNLOAD_URL has no protocol: %s\n' "$url" >&2
6161
return 1
62-
elif command -v cygpath >/dev/null && [[ "$protocol" == 'file' ]]; then
62+
elif [[ "$EXEPATH" =~ \\Git$ && "$protocol" == 'file' ]]; then
6363
url="file://$(cygpath -m "${url#file://}")"
6464
fi
6565

tests/template.bats

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ CLONE_DIR=
4242
setup() {
4343
test_filter
4444
export GO_SCRIPT_BASH_{VERSION,REPO_URL,DOWNLOAD_URL}
45-
NATIVE_LOCAL_URL="$(windows_native_path "$LOCAL_DOWNLOAD_URL")"
46-
CLONE_DIR="$(windows_native_path "$TEST_GO_SCRIPTS_DIR")/go-script-bash"
45+
NATIVE_LOCAL_URL="$(git_for_windows_native_path "$LOCAL_DOWNLOAD_URL")"
46+
CLONE_DIR="$(git_for_windows_native_path "$TEST_GO_SCRIPTS_DIR")"
47+
CLONE_DIR+='/go-script-bash'
4748
EXPECTED_URL="$FULL_DOWNLOAD_URL"
4849

4950
if [[ -z "$TEST_USE_REAL_URL" ]]; then
@@ -73,22 +74,22 @@ assert_go_core_unpacked() {
7374
restore_bats_shell_options "$result"
7475
}
7576

76-
# Converts a Unix path or 'file://' URL to a Windows native path.
77+
# Converts a Unix path or 'file://' URL to a Git for Windows native path.
7778
#
78-
# This is useful when passing file paths or URLs to native programs on MSYS2
79-
# or Cygwin, or validating the output of such programs, to ensure portability.
79+
# This is useful when passing file paths or URLs to native programs on Git for
80+
# Windows, or validating the output of such programs, to ensure portability.
8081
# The resulting path will contain forward slashes.
8182
#
8283
# Prints both converted and unconverted paths and URLs to standard output.
8384
#
8485
# Arguments:
8586
# path: Path or 'file://' URL to convert
86-
windows_native_path() {
87+
git_for_windows_native_path() {
8788
local path="$1"
8889
local protocol="${path%%://*}"
8990

90-
if ! command -v cygpath >/dev/null ||
91-
[[ "$protocol" != "$path" && "$protocol" != 'file' ]]; then
91+
if [[ ! "$EXEPATH" =~ \\Git$ && "$protocol" != "$path" &&
92+
"$protocol" != 'file' ]]; then
9293
printf '%s' "$path"
9394
elif [[ "$protocol" == 'file' ]]; then
9495
printf 'file://'

0 commit comments

Comments
 (0)