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_HOST_PORT
=127.0.0.1:$LIB_GIT_DAEMON_PORT
36 GIT_DAEMON_URL
=git
://$GIT_DAEMON_HOST_PORT
39 if test -n "$GIT_DAEMON_PID"
41 error
"start_git_daemon already called"
44 mkdir
-p "$GIT_DAEMON_DOCUMENT_ROOT_PATH"
46 trap 'code=$?; stop_git_daemon; (exit $code); die' EXIT
48 say
>&3 "Starting git daemon ..."
49 mkfifo git_daemon_output
50 ${LIB_GIT_DAEMON_COMMAND:-git daemon} \
51 --listen=127.0.0.1 --port="$LIB_GIT_DAEMON_PORT" \
52 --reuseaddr --verbose \
53 --base-path="$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
54 "$@" "$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
55 >&3 2>git_daemon_output
&
61 printf >&4 "%s\n" "$line"
63 while read -r line
<&7
66 printf >&4 "%s\n" "$line"
69 } 7<git_daemon_output
>>"$TRASH_DIRECTORY/daemon.log" &&
71 # Check expected output
72 if test x
"$(expr "$line" : "\
[[0-9]*\
] \
(.
*\
)")" != x
"Ready to rumble"
74 kill "$GIT_DAEMON_PID"
75 wait "$GIT_DAEMON_PID"
77 test_skip_or_die
$GIT_TEST_GIT_DAEMON \
78 "git daemon failed to start"
83 if test -z "$GIT_DAEMON_PID"
90 # kill git-daemon child of git
91 say
>&3 "Stopping git daemon ..."
92 kill "$GIT_DAEMON_PID"
93 wait "$GIT_DAEMON_PID" >&3 2>&4
95 if test_match_signal
15 $?
97 error
"git daemon exited with status: $ret"
100 rm -f git_daemon_output
103 # A stripped-down version of a netcat client, that connects to a "host:port"
104 # given in $1, sends its stdin followed by EOF, then dumps the response (until
107 if ! test_declared_prereq FAKENC
109 echo >&4 "fake_nc: need to declare FAKENC prerequisite"
112 perl
-Mstrict -MIO::Socket
::INET
-e '
113 my $s = IO::Socket::INET->new(shift)
114 or die "unable to open socket: $!";
121 test_lazy_prereq FAKENC
'
122 perl -MIO::Socket::INET -e "exit 0"