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 if test_have_prereq !PIPE
28 test_skip_or_die $GIT_TEST_GIT_DAEMON "file system does not support FIFOs"
31 LIB_GIT_DAEMON_PORT=${LIB_GIT_DAEMON_PORT-${this_test#t}}
34 GIT_DAEMON_DOCUMENT_ROOT_PATH="$PWD"/repo
35 GIT_DAEMON_URL=git://127.0.0.1:$LIB_GIT_DAEMON_PORT
38 if test -n "$GIT_DAEMON_PID"
40 error "start_git_daemon already called"
43 mkdir -p "$GIT_DAEMON_DOCUMENT_ROOT_PATH"
45 trap 'code=$?; stop_git_daemon; (exit $code); die' EXIT
47 say >&3 "Starting git daemon ..."
48 mkfifo git_daemon_output
49 ${LIB_GIT_DAEMON_COMMAND:-git daemon} \
50 --listen=127.0.0.1 --port="$LIB_GIT_DAEMON_PORT" \
51 --reuseaddr --verbose \
52 --base-path="$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
53 "$@" "$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
54 >&3 2>git_daemon_output &
60 } 7<git_daemon_output &&
62 # Check expected output
63 if test x"$(expr "$line" : "\[[0-9]*\] \(.*\)")" != x"Ready to rumble"
65 kill "$GIT_DAEMON_PID"
66 wait "$GIT_DAEMON_PID"
68 test_skip_or_die $GIT_TEST_GIT_DAEMON \
69 "git daemon failed to start"
74 if test -z "$GIT_DAEMON_PID"
81 # kill git-daemon child of git
82 say >&3 "Stopping git daemon ..."
83 kill "$GIT_DAEMON_PID"
84 wait "$GIT_DAEMON_PID" >&3 2>&4
86 if test_match_signal 15 $?
88 error "git daemon exited with status: $ret"
91 rm -f git_daemon_output