1 # Shell library to run git-daemon in tests. Ends the test early if
2 # GIT_TEST_GIT_DAEMON is not set.
7 # . "$TEST_DIRECTORY"/lib-git-daemon.sh
10 # test_expect_success '...' '
14 # test_expect_success ...
19 test_tristate GIT_TEST_GIT_DAEMON
20 if test "$GIT_TEST_GIT_DAEMON" = false
22 skip_all="git-daemon testing disabled (unset GIT_TEST_GIT_DAEMON to enable)"
26 LIB_GIT_DAEMON_PORT=${LIB_GIT_DAEMON_PORT-${this_test#t}}
29 GIT_DAEMON_DOCUMENT_ROOT_PATH="$PWD"/repo
30 GIT_DAEMON_URL=git://127.0.0.1:$LIB_GIT_DAEMON_PORT
33 if test -n "$GIT_DAEMON_PID"
35 error "start_git_daemon already called"
38 mkdir -p "$GIT_DAEMON_DOCUMENT_ROOT_PATH"
40 trap 'code=$?; stop_git_daemon; (exit $code); die' EXIT
42 say >&3 "Starting git daemon ..."
43 mkfifo git_daemon_output
44 git daemon --listen=127.0.0.1 --port="$LIB_GIT_DAEMON_PORT" \
45 --reuseaddr --verbose \
46 --base-path="$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
47 "$@" "$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
48 >&3 2>git_daemon_output &
54 } 7<git_daemon_output &&
56 # Check expected output
57 if test x"$(expr "$line" : "\[[0-9]*\] \(.*\)")" != x"Ready to rumble"
59 kill "$GIT_DAEMON_PID"
60 wait "$GIT_DAEMON_PID"
62 test_skip_or_die $GIT_TEST_GIT_DAEMON \
63 "git daemon failed to start"
68 if test -z "$GIT_DAEMON_PID"
75 # kill git-daemon child of git
76 say >&3 "Stopping git daemon ..."
77 kill "$GIT_DAEMON_PID"
78 wait "$GIT_DAEMON_PID" >&3 2>&4
80 # expect exit with status 143 = 128+15 for signal TERM=15
83 error "git daemon exited with status: $ret"
86 rm -f git_daemon_output