Skip to content

Commit fc55a10

Browse files
committed
go-template: Use git to detect Git for Windows
Turns out this is the most reliable and robust way, as `EXEPATH` won't always be set or set with 'Git' as its final component.
1 parent 757cf46 commit fc55a10

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
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 [[ "$EXEPATH" =~ \\Git$ && "$protocol" == 'file' ]]; then
62+
elif [[ "$(git --version)" =~ windows && "$protocol" == 'file' ]]; then
6363
url="file://$(cygpath -m "${url#file://}")"
6464
fi
6565

tests/template.bats

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ setup() {
5151
EXPECTED_URL="$NATIVE_LOCAL_URL"
5252
fi
5353

54-
# Ensure `cygpath` is always available if we need it.
54+
# Ensure `cygpath` and `git` are always available if we need them.
5555
create_forwarding_script 'cygpath'
56+
create_forwarding_script 'git'
5657

5758
mkdir -p "$TEST_GO_ROOTDIR"
5859
cp "$_GO_CORE_DIR/go-template" "$TEST_GO_ROOTDIR"
@@ -88,7 +89,7 @@ git_for_windows_native_path() {
8889
local path="$1"
8990
local protocol="${path%%://*}"
9091

91-
if [[ ! "$EXEPATH" =~ \\Git$ ]] ||
92+
if [[ ! "$(git --version)" =~ windows ]] ||
9293
[[ "$protocol" != "$path" && "$protocol" != 'file' ]]; then
9394
printf '%s' "$path"
9495
elif [[ "$protocol" == 'file' ]]; then
@@ -324,7 +325,6 @@ run_with_download_program() {
324325
}
325326

326327
@test "$SUITE: fail to find download program uses git clone" {
327-
create_forwarding_script 'git'
328328
PATH="$BATS_TEST_BINDIR" run "$BASH" "$TEST_GO_ROOTDIR/go-template"
329329

330330
assert_output_matches "Failed to find cURL, wget, or fetch"
@@ -336,7 +336,6 @@ run_with_download_program() {
336336

337337
@test "$SUITE: fail to find tar uses git clone" {
338338
create_forwarding_script 'curl'
339-
create_forwarding_script 'git'
340339
PATH="$BATS_TEST_BINDIR" run "$BASH" "$TEST_GO_ROOTDIR/go-template"
341340

342341
assert_output_matches "Failed to find tar"

0 commit comments

Comments
 (0)