3 test_description='credential-cache tests'
5 . "$TEST_DIRECTORY"/lib-credential.sh
7 test -z "$NO_UNIX_SOCKETS" || {
8 skip_all='skipping credential-cache tests, unix sockets not available'
12 # don't leave a stale daemon running
13 test_atexit 'git credential-cache exit'
15 # test that the daemon works with no special setup
18 test_expect_success 'socket defaults to ~/.cache/git/credential/socket' '
20 git credential-cache exit &&
21 rmdir -p .cache/git/credential/
23 test_path_is_missing "$HOME/.git-credential-cache" &&
24 test -S "$HOME/.cache/git/credential/socket"
27 XDG_CACHE_HOME="$HOME/xdg"
29 # test behavior when XDG_CACHE_HOME is set
32 test_expect_success "use custom XDG_CACHE_HOME if set and default sockets are not created" '
33 test_when_finished "git credential-cache exit" &&
34 test -S "$XDG_CACHE_HOME/git/credential/socket" &&
35 test_path_is_missing "$HOME/.git-credential-cache/socket" &&
36 test_path_is_missing "$HOME/.cache/git/credential/socket"
40 test_expect_success 'credential-cache --socket option overrides default location' '
42 git credential-cache exit --socket \"\$HOME/dir/socket\" &&
45 check approve "cache --socket \"\$HOME/dir/socket\"" <<-\EOF &&
51 test -S "$HOME/dir/socket"
54 test_expect_success "use custom XDG_CACHE_HOME even if xdg socket exists" '
56 git credential-cache exit &&
57 sane_unset XDG_CACHE_HOME
59 check approve cache <<-\EOF &&
65 test -S "$HOME/.cache/git/credential/socket" &&
66 XDG_CACHE_HOME="$HOME/xdg" &&
67 export XDG_CACHE_HOME &&
68 check approve cache <<-\EOF &&
74 test -S "$XDG_CACHE_HOME/git/credential/socket"
77 test_expect_success 'use user socket if user directory exists' '
79 git credential-cache exit &&
80 rmdir \"\$HOME/.git-credential-cache/\"
82 mkdir -p -m 700 "$HOME/.git-credential-cache/" &&
83 check approve cache <<-\EOF &&
89 test -S "$HOME/.git-credential-cache/socket"
92 test_expect_success SYMLINKS 'use user socket if user directory is a symlink to a directory' '
94 git credential-cache exit &&
95 rmdir \"\$HOME/dir/\" &&
96 rm \"\$HOME/.git-credential-cache\"
98 mkdir -p -m 700 "$HOME/dir/" &&
99 ln -s "$HOME/dir" "$HOME/.git-credential-cache" &&
100 check approve cache <<-\EOF &&
106 test -S "$HOME/.git-credential-cache/socket"
109 helper_test_timeout cache --timeout=1