Skip to content

Commit 0fdcfa2

Browse files
carenasgitster
authored andcommitted
t0301: fixes for windows compatibility
In preparation for a future patch that will allow building with Unix Sockets in Windows, workaround a couple of issues from the Mingw-W64 compatibility layer. test -S is not able to detect that a file is a socket, so use test -e instead (through a library function). `mkdir -m` can't represent a valid ACL directly and fails with permission problems, so instead call mkdir followed by chmod, which has been enhanced to do so. The last invocation of mkdir would likely need the same treatment but SYMLINK is unlikely to be enabled on Windows so it has been punted for now. Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 8b7c11b commit 0fdcfa2

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

t/t0301-credential-cache.sh

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,21 @@ test -z "$NO_UNIX_SOCKETS" || {
99
test_done
1010
}
1111

12+
uname_s=$(uname -s)
13+
case $uname_s in
14+
*MINGW*)
15+
test_path_is_socket () {
16+
# `test -S` cannot detect Win10's Unix sockets
17+
test_path_exists "$1"
18+
}
19+
;;
20+
*)
21+
test_path_is_socket () {
22+
test -S "$1"
23+
}
24+
;;
25+
esac
26+
1227
# don't leave a stale daemon running
1328
test_atexit 'git credential-cache exit'
1429

@@ -21,7 +36,7 @@ test_expect_success 'socket defaults to ~/.cache/git/credential/socket' '
2136
rmdir -p .cache/git/credential/
2237
" &&
2338
test_path_is_missing "$HOME/.git-credential-cache" &&
24-
test -S "$HOME/.cache/git/credential/socket"
39+
test_path_is_socket "$HOME/.cache/git/credential/socket"
2540
'
2641

2742
XDG_CACHE_HOME="$HOME/xdg"
@@ -31,7 +46,7 @@ helper_test cache
3146

3247
test_expect_success "use custom XDG_CACHE_HOME if set and default sockets are not created" '
3348
test_when_finished "git credential-cache exit" &&
34-
test -S "$XDG_CACHE_HOME/git/credential/socket" &&
49+
test_path_is_socket "$XDG_CACHE_HOME/git/credential/socket" &&
3550
test_path_is_missing "$HOME/.git-credential-cache/socket" &&
3651
test_path_is_missing "$HOME/.cache/git/credential/socket"
3752
'
@@ -48,7 +63,7 @@ test_expect_success 'credential-cache --socket option overrides default location
4863
username=store-user
4964
password=store-pass
5065
EOF
51-
test -S "$HOME/dir/socket"
66+
test_path_is_socket "$HOME/dir/socket"
5267
'
5368

5469
test_expect_success "use custom XDG_CACHE_HOME even if xdg socket exists" '
@@ -62,7 +77,7 @@ test_expect_success "use custom XDG_CACHE_HOME even if xdg socket exists" '
6277
username=store-user
6378
password=store-pass
6479
EOF
65-
test -S "$HOME/.cache/git/credential/socket" &&
80+
test_path_is_socket "$HOME/.cache/git/credential/socket" &&
6681
XDG_CACHE_HOME="$HOME/xdg" &&
6782
export XDG_CACHE_HOME &&
6883
check approve cache <<-\EOF &&
@@ -71,22 +86,23 @@ test_expect_success "use custom XDG_CACHE_HOME even if xdg socket exists" '
7186
username=store-user
7287
password=store-pass
7388
EOF
74-
test -S "$XDG_CACHE_HOME/git/credential/socket"
89+
test_path_is_socket "$XDG_CACHE_HOME/git/credential/socket"
7590
'
7691

7792
test_expect_success 'use user socket if user directory exists' '
7893
test_when_finished "
7994
git credential-cache exit &&
8095
rmdir \"\$HOME/.git-credential-cache/\"
8196
" &&
82-
mkdir -p -m 700 "$HOME/.git-credential-cache/" &&
97+
mkdir -p "$HOME/.git-credential-cache/" &&
98+
chmod 700 "$HOME/.git-credential-cache/" &&
8399
check approve cache <<-\EOF &&
84100
protocol=https
85101
host=example.com
86102
username=store-user
87103
password=store-pass
88104
EOF
89-
test -S "$HOME/.git-credential-cache/socket"
105+
test_path_is_socket "$HOME/.git-credential-cache/socket"
90106
'
91107

92108
test_expect_success SYMLINKS 'use user socket if user directory is a symlink to a directory' '
@@ -103,7 +119,7 @@ test_expect_success SYMLINKS 'use user socket if user directory is a symlink to
103119
username=store-user
104120
password=store-pass
105121
EOF
106-
test -S "$HOME/.git-credential-cache/socket"
122+
test_path_is_socket "$HOME/.git-credential-cache/socket"
107123
'
108124

109125
helper_test_timeout cache --timeout=1

0 commit comments

Comments
 (0)