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>
Carlo Marcelo Arenas Belón committed
Sep 14, 2021 at 00:25 UTC
0fdcfa2f9f59a8bf4202ac3933991f42a4ac1393
1 file changed
+24
-8
t/t0301-credential-cache.sh
+24
-8
@@ -9,6 +9,21 @@ test -z "$NO_UNIX_SOCKETS" || {
9
test_done
10
}
11
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
+
27
# don't leave a stale daemon running
28
test_atexit 'git credential-cache exit'
29
@@ -21,7 +36,7 @@ test_expect_success 'socket defaults to ~/.cache/git/credential/socket' '
36
rmdir -p .cache/git/credential/
37
" &&
38
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"
40
'
41
42
XDG_CACHE_HOME="$HOME/xdg"
@@ -31,7 +46,7 @@ helper_test cache
46
47
test_expect_success "use custom XDG_CACHE_HOME if set and default sockets are not created" '
48
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" &&
50
test_path_is_missing "$HOME/.git-credential-cache/socket" &&
51
test_path_is_missing "$HOME/.cache/git/credential/socket"
52
'
@@ -48,7 +63,7 @@ test_expect_success 'credential-cache --socket option overrides default location
63
username=store-user
64
password=store-pass
65
EOF
51
- test -S "$HOME/dir/socket"
66
+ test_path_is_socket "$HOME/dir/socket"
67
'
68
69
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" '
77
username=store-user
78
password=store-pass
79
EOF
65
- test -S "$HOME/.cache/git/credential/socket" &&
80
+ test_path_is_socket "$HOME/.cache/git/credential/socket" &&
81
XDG_CACHE_HOME="$HOME/xdg" &&
82
export XDG_CACHE_HOME &&
83
check approve cache <<-\EOF &&
@@ -71,7 +86,7 @@ test_expect_success "use custom XDG_CACHE_HOME even if xdg socket exists" '
86
username=store-user
87
password=store-pass
88
EOF
74
- test -S "$XDG_CACHE_HOME/git/credential/socket"
89
+ test_path_is_socket "$XDG_CACHE_HOME/git/credential/socket"
90
'
91
92
test_expect_success 'use user socket if user directory exists' '
@@ -79,14 +94,15 @@ test_expect_success 'use user socket if user directory exists' '
94
git credential-cache exit &&
95
rmdir \"\$HOME/.git-credential-cache/\"
96
" &&
82
- mkdir -p -m 700 "$HOME/.git-credential-cache/" &&
97
+ mkdir -p "$HOME/.git-credential-cache/" &&
98
+ chmod 700 "$HOME/.git-credential-cache/" &&
99
check approve cache <<-\EOF &&
100
protocol=https
101
host=example.com
102
username=store-user
103
password=store-pass
104
EOF
89
- test -S "$HOME/.git-credential-cache/socket"
105
+ test_path_is_socket "$HOME/.git-credential-cache/socket"
106
'
107
108
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
119
username=store-user
120
password=store-pass
121
EOF
106
- test -S "$HOME/.git-credential-cache/socket"
122
+ test_path_is_socket "$HOME/.git-credential-cache/socket"
123
'
124
125
helper_test_timeout cache --timeout=1