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 ...
18 if ! test_bool_env GIT_TEST_GIT_DAEMON true
20 skip_all
="git-daemon testing disabled (unset GIT_TEST_GIT_DAEMON to enable)"
24 if test_have_prereq
!PIPE
26 test_skip_or_die GIT_TEST_GIT_DAEMON
"file system does not support FIFOs"
29 test_set_port LIB_GIT_DAEMON_PORT
32 GIT_DAEMON_PIDFILE
="$PWD"/daemon.pid
33 GIT_DAEMON_DOCUMENT_ROOT_PATH
="$PWD"/repo
34 GIT_DAEMON_HOST_PORT
=127.0.0.1:$LIB_GIT_DAEMON_PORT
35 GIT_DAEMON_URL
=git
://$GIT_DAEMON_HOST_PORT
37 registered_stop_git_daemon_atexit_handler
=
39 if test -n "$GIT_DAEMON_PID"
41 error
"start_git_daemon already called"
44 mkdir
-p "$GIT_DAEMON_DOCUMENT_ROOT_PATH"
46 # One of the test scripts stops and then re-starts 'git daemon'.
47 # Don't register and then run the same atexit handlers several times.
48 if test -z "$registered_stop_git_daemon_atexit_handler"
50 test_atexit
'stop_git_daemon'
51 registered_stop_git_daemon_atexit_handler
=AlreadyDone
54 say
>&3 "Starting git daemon ..."
55 mkfifo git_daemon_output
56 ${LIB_GIT_DAEMON_COMMAND:-git daemon} \
57 --listen=127.0.0.1 --port="$LIB_GIT_DAEMON_PORT" \
58 --reuseaddr --verbose --pid-file="$GIT_DAEMON_PIDFILE" \
59 --base-path="$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
60 "$@" "$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
61 >&3 2>git_daemon_output
&
65 printf "%s\n" "$line" >&4
67 } 7<git_daemon_output
&&
69 # Check expected output
70 if test x
"$(expr "$line" : "\
[[0-9]*\
] \
(.
*\
)")" != x
"Ready to rumble"
72 kill "$GIT_DAEMON_PID"
73 wait "$GIT_DAEMON_PID"
75 test_skip_or_die GIT_TEST_GIT_DAEMON \
76 "git daemon failed to start"
81 if test -z "$GIT_DAEMON_PID"
86 # kill git-daemon child of git
87 say
>&3 "Stopping git daemon ..."
88 kill "$GIT_DAEMON_PID"
89 wait "$GIT_DAEMON_PID" >&3 2>&4
91 if ! test_match_signal
15 $ret
93 error
"git daemon exited with status: $ret"
95 kill "$(cat "$GIT_DAEMON_PIDFILE")" 2>/dev
/null
97 rm -f git_daemon_output
"$GIT_DAEMON_PIDFILE"
100 # A stripped-down version of a netcat client, that connects to a "host:port"
101 # given in $1, sends its stdin followed by EOF, then dumps the response (until
104 if ! test_declared_prereq FAKENC
106 echo >&4 "fake_nc: need to declare FAKENC prerequisite"
109 perl
-Mstrict -MIO::Socket
::INET
-e '
110 my $s = IO::Socket::INET->new(shift)
111 or die "unable to open socket: $!";
118 test_lazy_prereq FAKENC
'
119 perl -MIO::Socket::INET -e "exit 0"