Skip to content

Commit c2e7990

Browse files
committed
Merge branch 'cb/unix-sockets-with-windows'
Adjust credential-cache helper to Windows. * cb/unix-sockets-with-windows: git-compat-util: include declaration for unix sockets in windows credential-cache: check for windows specific errors t0301: fixes for windows compatibility
2 parents 0e35107 + bb390b1 commit c2e7990

File tree

3 files changed

+55
-10
lines changed

3 files changed

+55
-10
lines changed

builtin/credential-cache.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,32 @@
1111
#define FLAG_SPAWN 0x1
1212
#define FLAG_RELAY 0x2
1313

14+
#ifdef GIT_WINDOWS_NATIVE
15+
16+
static int connection_closed(int error)
17+
{
18+
return (error == EINVAL);
19+
}
20+
21+
static int connection_fatally_broken(int error)
22+
{
23+
return (error != ENOENT) && (error != ENETDOWN);
24+
}
25+
26+
#else
27+
28+
static int connection_closed(int error)
29+
{
30+
return (error == ECONNRESET);
31+
}
32+
33+
static int connection_fatally_broken(int error)
34+
{
35+
return (error != ENOENT) && (error != ECONNREFUSED);
36+
}
37+
38+
#endif
39+
1440
static int send_request(const char *socket, const struct strbuf *out)
1541
{
1642
int got_data = 0;
@@ -28,7 +54,7 @@ static int send_request(const char *socket, const struct strbuf *out)
2854
int r;
2955

3056
r = read_in_full(fd, in, sizeof(in));
31-
if (r == 0 || (r < 0 && errno == ECONNRESET))
57+
if (r == 0 || (r < 0 && connection_closed(errno)))
3258
break;
3359
if (r < 0)
3460
die_errno("read error from cache daemon");
@@ -75,7 +101,7 @@ static void do_cache(const char *socket, const char *action, int timeout,
75101
}
76102

77103
if (send_request(socket, &buf) < 0) {
78-
if (errno != ENOENT && errno != ECONNREFUSED)
104+
if (connection_fatally_broken(errno))
79105
die_errno("unable to connect to cache daemon");
80106
if (flags & FLAG_SPAWN) {
81107
spawn_daemon(socket);

git-compat-util.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@
160160
# endif
161161
#define WIN32_LEAN_AND_MEAN /* stops windows.h including winsock.h */
162162
#include <winsock2.h>
163+
#ifndef NO_UNIX_SOCKETS
164+
#include <afunix.h>
165+
#endif
163166
#include <windows.h>
164167
#define GIT_WINDOWS_NATIVE
165168
#endif

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)