Skip to content

Commit

Permalink
TO-SPLIT
Browse files Browse the repository at this point in the history
A proof-of-concept how to test for `git push` via `git://`, intended as
a starter patch for git-for-windows#2375.

Signed-off-by: Johannes Schindelin <[email protected]>
  • Loading branch information
dscho committed Oct 27, 2019
1 parent e900821 commit fd4bd1e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
14 changes: 14 additions & 0 deletions daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ static enum log_destination {
LOG_DESTINATION_STDERR = 1,
LOG_DESTINATION_SYSLOG = 2,
} log_destination = LOG_DESTINATION_UNSET;
static FILE *log_tee_file;
static int verbose;
static int reuseaddr;
static int informative_errors;
Expand Down Expand Up @@ -88,6 +89,13 @@ static void logreport(int priority, const char *err, va_list params)
break;
}
case LOG_DESTINATION_STDERR:
if (log_tee_file) {
fprintf(log_tee_file, "[%"PRIuMAX"] ",
(uintmax_t)getpid());
vfprintf(log_tee_file, err, params);
fputc('\n', log_tee_file);
fflush(log_tee_file);
}
/*
* Since stderr is set to buffered mode, the
* logging of different processes will not overlap
Expand Down Expand Up @@ -1317,6 +1325,12 @@ int cmd_main(int argc, const char **argv)
} else if (!strcmp(v, "stderr")) {
log_destination = LOG_DESTINATION_STDERR;
continue;
} else if (skip_prefix(v, "tee:", &v)) {
log_destination = LOG_DESTINATION_STDERR;
if (log_tee_file)
fclose(log_tee_file);
log_tee_file = xfopen(v, "a");
continue;
} else if (!strcmp(v, "none")) {
log_destination = LOG_DESTINATION_NONE;
continue;
Expand Down
23 changes: 10 additions & 13 deletions t/lib-git-daemon.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ then
test_done
fi

if test_have_prereq !PIPE
then
test_skip_or_die GIT_TEST_GIT_DAEMON "file system does not support FIFOs"
fi

test_set_port LIB_GIT_DAEMON_PORT

GIT_DAEMON_PID=
Expand All @@ -52,21 +47,23 @@ start_git_daemon() {
fi

say >&3 "Starting git daemon ..."
mkfifo git_daemon_output
${LIB_GIT_DAEMON_COMMAND:-git daemon} \
--listen=127.0.0.1 --port="$LIB_GIT_DAEMON_PORT" \
--reuseaddr --verbose --pid-file="$GIT_DAEMON_PIDFILE" \
--log-destination=tee:git_daemon_output \
--base-path="$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
"$@" "$GIT_DAEMON_DOCUMENT_ROOT_PATH" \
>&3 2>git_daemon_output &
>&3 2>&4 &
GIT_DAEMON_PID=$!
{
read -r line <&7
printf "%s\n" "$line" >&4
cat <&7 >&4 &
} 7<git_daemon_output &&

# Wait for the first line in the output
while test ! -s git_daemon_output
do
sleep 1
done

# Check expected output
read -r line <git_daemon_output
if test x"$(expr "$line" : "\[[0-9]*\] \(.*\)")" != x"Ready to rumble"
then
kill "$GIT_DAEMON_PID"
Expand All @@ -88,7 +85,7 @@ stop_git_daemon() {
kill "$GIT_DAEMON_PID"
wait "$GIT_DAEMON_PID" >&3 2>&4
ret=$?
if ! test_match_signal 15 $ret
if ! test_match_signal 15 $ret && test 127 != $ret
then
error "git daemon exited with status: $ret"
fi
Expand Down
7 changes: 6 additions & 1 deletion t/t5700-protocol-v1.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ test_expect_success 'pull with git:// using protocol v1' '
test_expect_success 'push with git:// using protocol v1' '
test_commit -C daemon_child three &&
if test_have_prereq MINGW
then
test_config -C daemon_child sendpack.sideband false
fi &&
# Push to another branch, as the target repository has the
# master branch checked out and we cannot push into it.
GIT_TRACE_PACKET=1 git -C daemon_child -c protocol.version=1 \
Expand Down Expand Up @@ -169,7 +174,7 @@ test_expect_success 'create repo to be served by ssh:// transport' '

test_expect_success 'clone with ssh:// using protocol v1' '
GIT_TRACE_PACKET=1 git -c protocol.version=1 \
clone "ssh://myhost:$(pwd)/ssh_parent" ssh_child 2>log &&
clone "ssh://myhost:$PWD/ssh_parent" ssh_child 2>log &&
expect_ssh git-upload-pack &&
git -C ssh_child log -1 --format=%s >actual &&
Expand Down

0 comments on commit fd4bd1e

Please sign in to comment.