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 test_set_port LIB_GIT_DAEMON_PORT
34 GIT_DAEMON_PIDFILE="$PWD"/daemon.pid
35 GIT_DAEMON_DOCUMENT_ROOT_PATH="$PWD"/repo
36 GIT_DAEMON_HOST_PORT=127.0.0.1:$LIB_GIT_DAEMON_PORT
37 GIT_DAEMON_URL=git://$GIT_DAEMON_HOST_PORT
40 if test -n "$GIT_DAEMON_PID"
42 error "start_git_daemon already called"
45 mkdir -p "$GIT_DAEMON_DOCUMENT_ROOT_PATH"
47 trap 'code=$?; stop_git_daemon; (exit $code); die' EXIT
49 say >&3 "Starting git daemon ..."
50 mkfifo git_daemon_output
51 ${LIB_GIT_DAEMON_COMMAND:-git daemon} \
52 --listen=127.0.0.1 --port="$LIB_GIT_DAEMON_PORT" \
53 --reuseaddr --verbose --pid-file="$GIT_DAEMON_PIDFILE" \
54 --base-path="$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
55 "$@" "$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
56 >&3 2>git_daemon_output &
60 printf "%s\n" "$line" >&4
62 } 7<git_daemon_output &&
64 # Check expected output
65 if test x"$(expr "$line" : "\[[0-9]*\] \(.*\)")" != x"Ready to rumble"
67 kill "$GIT_DAEMON_PID"
68 wait "$GIT_DAEMON_PID"
70 test_skip_or_die $GIT_TEST_GIT_DAEMON \
71 "git daemon failed to start"
76 if test -z "$GIT_DAEMON_PID"
83 # kill git-daemon child of git
84 say >&3 "Stopping git daemon ..."
85 kill "$GIT_DAEMON_PID"
86 wait "$GIT_DAEMON_PID" >&3 2>&4
88 if ! test_match_signal 15 $ret
90 error "git daemon exited with status: $ret"
92 kill "$(cat "$GIT_DAEMON_PIDFILE")" 2>/dev/null
94 rm -f git_daemon_output "$GIT_DAEMON_PIDFILE"
97 # A stripped-down version of a netcat client, that connects to a "host:port"
98 # given in $1, sends its stdin followed by EOF, then dumps the response (until
101 if ! test_declared_prereq FAKENC
103 echo >&4 "fake_nc: need to declare FAKENC prerequisite"
106 perl -Mstrict -MIO::Socket::INET -e '
107 my $s = IO::Socket::INET->new(shift)
108 or die "unable to open socket: $!";
115 test_lazy_prereq FAKENC '
116 perl -MIO::Socket::INET -e "exit 0"