]> git.ipfire.org Git - thirdparty/git.git/blame - t/lib-git-daemon.sh
Git 2.14.4
[thirdparty/git.git] / t / lib-git-daemon.sh
CommitLineData
c74c7203
JN
1# Shell library to run git-daemon in tests. Ends the test early if
2# GIT_TEST_GIT_DAEMON is not set.
3#
4# Usage:
5#
6# . ./test-lib.sh
7# . "$TEST_DIRECTORY"/lib-git-daemon.sh
8# start_git_daemon
9#
10# test_expect_success '...' '
11# ...
12# '
13#
14# test_expect_success ...
15#
16# stop_git_daemon
17# test_done
71039fb9 18
83d842dc
JK
19test_tristate GIT_TEST_GIT_DAEMON
20if test "$GIT_TEST_GIT_DAEMON" = false
71039fb9 21then
83d842dc 22 skip_all="git-daemon testing disabled (unset GIT_TEST_GIT_DAEMON to enable)"
71039fb9
CB
23 test_done
24fi
25
a390d7e8
JS
26if test_have_prereq !PIPE
27then
28 test_skip_or_die $GIT_TEST_GIT_DAEMON "file system does not support FIFOs"
29fi
30
c44132fc 31LIB_GIT_DAEMON_PORT=${LIB_GIT_DAEMON_PORT-${this_test#t}}
71039fb9
CB
32
33GIT_DAEMON_PID=
34GIT_DAEMON_DOCUMENT_ROOT_PATH="$PWD"/repo
35GIT_DAEMON_URL=git://127.0.0.1:$LIB_GIT_DAEMON_PORT
36
37start_git_daemon() {
38 if test -n "$GIT_DAEMON_PID"
39 then
40 error "start_git_daemon already called"
41 fi
42
43 mkdir -p "$GIT_DAEMON_DOCUMENT_ROOT_PATH"
44
45 trap 'code=$?; stop_git_daemon; (exit $code); die' EXIT
46
47 say >&3 "Starting git daemon ..."
561b133c 48 mkfifo git_daemon_output
bd4d9d99
JK
49 ${LIB_GIT_DAEMON_COMMAND:-git daemon} \
50 --listen=127.0.0.1 --port="$LIB_GIT_DAEMON_PORT" \
71039fb9
CB
51 --reuseaddr --verbose \
52 --base-path="$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
53 "$@" "$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
561b133c 54 >&3 2>git_daemon_output &
71039fb9 55 GIT_DAEMON_PID=$!
561b133c 56 {
46e35815 57 read line <&7
561b133c 58 echo >&4 "$line"
46e35815
JS
59 cat <&7 >&4 &
60 } 7<git_daemon_output &&
561b133c 61
46e35815
JS
62 # Check expected output
63 if test x"$(expr "$line" : "\[[0-9]*\] \(.*\)")" != x"Ready to rumble"
64 then
65 kill "$GIT_DAEMON_PID"
66 wait "$GIT_DAEMON_PID"
67 trap 'die' EXIT
83d842dc
JK
68 test_skip_or_die $GIT_TEST_GIT_DAEMON \
69 "git daemon failed to start"
46e35815 70 fi
71039fb9
CB
71}
72
73stop_git_daemon() {
74 if test -z "$GIT_DAEMON_PID"
75 then
76 return
77 fi
78
79 trap 'die' EXIT
80
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
85 ret=$?
03c39b34 86 if test_match_signal 15 $?
71039fb9
CB
87 then
88 error "git daemon exited with status: $ret"
89 fi
90 GIT_DAEMON_PID=
561b133c 91 rm -f git_daemon_output
71039fb9 92}