8000 Implement push options on push by russell · Pull Request #6439 · libgit2/libgit2 · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
ci: update push options tests
Keep the push options tests more constrained to our CI environment;
writing files within the test sandbox instead of outside of it. Provide
the path to the output file in the test data. In addition, add the
repository to the test resources instead of recreating the hooks every
time.
  • Loading branch information
ethomson committed Feb 6, 2024
commit 85279f06aae1796d1551609041c5e0cf691bb297
2 changes: 0 additions & 2 deletions ci/hooks/pre-receive

This file was deleted.

60 changes: 15 additions & 45 deletions ci/test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

set -ex
set -e

if [ -n "$SKIP_TESTS" ]; then
if [ -z "$SKIP_OFFLINE_TESTS" ]; then SKIP_OFFLINE_TESTS=1; fi
Expand Down Expand Up @@ -162,14 +162,7 @@ echo ""
if should_run "GITDAEMON_TESTS"; then
echo "Starting git daemon (standard)..."
GIT_STANDARD_DIR=`mktemp -d ${TMPDIR}/git_standard.XXXXXXXX`
git init --bare "${GIT_STANDARD_DIR}/test.git" >/dev/null
git config --file "${GIT_STANDARD_DIR}/test.git/config" receive.advertisePushOptions true
for f in $(ls ${SOURCE_DIR}/ci/hooks)
do
sed "s=%file%=${TMPDIR}/push-option-result-git-daemon=g" "${SOURCE_DIR}/ci/hooks/$f" > "${GIT_STANDARD_DIR}/test.git/hooks/${f}"
chmod +x "$GIT_STANDARD_DIR/test.git/hooks/${f}"
done

cp -R "${SOURCE_DIR}/tests/resources/pushoptions.git" "${GIT_STANDARD_DIR}/test.git"
git daemon --listen=localhost --export-all --enable=receive-pack --base-path="${GIT_STANDARD_DIR}" "${GIT_STANDARD_DIR}" 2>/dev/null &

GIT_STANDARD_PID=$!
Expand Down Expand Up @@ -204,14 +197,7 @@ if should_run "NTLM_TESTS" || should_run "ONLINE_TESTS"; then

echo "Starting HTTP server..."
HTTP_DIR=`mktemp -d ${TMPDIR}/http.XXXXXXXX`
git init --bare "${HTTP_DIR}/test.git"
git config --file "${HTTP_DIR}/test.git/config" receive.advertisePushOptions true

for f in $(ls ${SOURCE_DIR}/ci/hooks)
do
sed "s=%file%=${TMPDIR}/push-option-result-git-ntlm=g" "${SOURCE_DIR}/ci/hooks/$f" > "${HTTP_DIR}/test.git/hooks/${f}"
chmod +x "$HTTP_DIR/test.git/hooks/${f}"
done
cp -R "${SOURCE_DIR}/tests/resources/pushoptions.git" "${HTTP_DIR}/test.git"

java -jar poxygit.jar --address 127.0.0.1 --port 9000 --credentials foo:baz --quiet "${HTTP_DIR}" &
HTTP_PID=$!
Expand All @@ -220,14 +206,8 @@ fi
if should_run "SSH_TESTS"; then
echo "Starting SSH server..."
SSHD_DIR=`mktemp -d ${TMPDIR}/sshd.XXXXXXXX`
git init --bare "${SSHD_DIR}/test.git" >/dev/null
git config --file "${SSHD_DIR}/test.git/config" receive.advertisePushOptions true

for f in $(ls ${SOURCE_DIR}/ci/hooks)
do
sed "s=%file%=${TMPDIR}/push-option-result-git-ssh=g" "${SOURCE_DIR}/ci/hooks/$f" > "${SSHD_DIR}/test.git/hooks/${f}"
chmod +x "$SSHD_DIR/test.git/hooks/${f}"
done
cp -R "${SOURCE_DIR}/tests/resources/pushoptions.git" "${SSHD_DIR}/test.git"
ls -FlasR "${SSHD_DIR}"

cat >"${SSHD_DIR}/sshd_config" <<-EOF
Port 2222
Expand Down Expand Up @@ -344,13 +324,11 @@ if should_run "GITDAEMON_TESTS"; then
echo "Running gitdaemon (standard) tests"
echo ""

if [[ "$RUN_PUSH_OPTONS_TESTS" = "true " ]]; then
export GITTEST_PUSH_OPTION_RESULT="${TMPDIR}/push-option-result-git-daemon"
fi
export GITTEST_REMOTE_URL="git://localhost/test.git"
export GITTEST_PUSH_OPTIONS=true
run_test gitdaemon
unset GITTEST_PUSH_OPTION_RESULT
unset GITTEST_REMOTE_URL
unset GITTEST_PUSH_OPTIONS

echo ""
echo "Running gitdaemon (namespace) tests"
Expand Down Expand Up @@ -402,33 +380,29 @@ if should_run "NTLM_TESTS"; then
echo "Running NTLM tests (IIS emulation)"
echo ""

if [[ "$RUN_PUSH_OPTONS_TESTS" = "true " ]]; then
export GITTEST_PUSH_OPTION_RESULT="${TMPDIR}/push-option-result-git-ntlm"
fi
export GITTEST_REMOTE_URL="http://localhost:9000/ntlm/test.git"
export GITTEST_REMOTE_USER="foo"
export GITTEST_REMOTE_PASS="baz"
export GITTEST_PUSH_OPTIONS=true
run_test auth_clone_and_push
unset GITTEST_PUSH_OPTION_RESULT
unset GITTEST_REMOTE_URL
unset GITTEST_REMOTE_USER
unset GITTEST_REMOTE_PASS
unset GITTEST_PUSH_OPTIONS

echo ""
echo "Running NTLM tests (Apache emulation)"
echo ""

if [[ "$RUN_PUSH_OPTONS_TESTS" == "true " ]]; then
export GITTEST_PUSH_OPTION_RESULT="${TMPDIR}/push-option-result-git-ntlm"
fi
export GITTEST_REMOTE_URL="http://localhost:9000/broken-ntlm/test.git"
export GITTEST_REMOTE_USER="foo"
export GITTEST_REMOTE_PASS="baz"
export GITTEST_PUSH_OPTIONS=true
run_test auth_clone_and_push
unset GITTEST_PUSH_OPTION_RESULT
unset GITTEST_REMOTE_URL
unset GITTEST_REMOTE_USER
unset GITTEST_REMOTE_PASS
unset GITTEST_PUSH_OPTIONS
fi

if should_run "NEGOTIATE_TESTS" && -n "$GITTEST_NEGOTIATE_PASSWORD" ; then
Expand Down Expand Up @@ -477,25 +451,21 @@ if should_run "SSH_TESTS"; then
echo "Running ssh tests"
echo ""

if [[ "$RUN_PUSH_OPTONS_TESTS" == "true " ]]; then
export GITTEST_PUSH_OPTION_RESULT="${TMPDIR}/push-option-result-ssh"
fi
export GITTEST_REMOTE_URL="ssh://localhost:2222/$SSHD_DIR/test.git"
export GITTEST_PUSH_OPTIONS=true
run_test ssh
unset GITTEST_PUSH_OPTION_RESULT
unset GITTEST_REMOTE_URL
unset GITTEST_PUSH_OPTIONS

echo ""
echo "Running ssh tests (scp-style paths)"
echo ""

if [[ "$RUN_PUSH_OPTONS_TESTS" == "true " ]]; then
export GITTEST_PUSH_OPTION_RESULT="${TMPDIR}/push-option-result-ssh"
fi
export GITTEST_REMOTE_URL="[localhost:2222]:$SSHD_DIR/test.git"
export GITTEST_PUSH_OPTIONS=true
run_test ssh
unset GITTEST_PUSH_OPTION_RESULT
unset GITTEST_REMOTE_URL
unset GITTEST_PUSH_OPTIONS

unset GITTEST_SSH_CMD

Expand Down
34 changes: 23 additions & 11 deletions tests/libgit2/online/push.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ static char *_remote_ssh_passphrase = NULL;
static char *_remote_default = NULL;
static char *_remote_expectcontinue = NULL;

static char *_remote_push_options = NULL;

static char *_orig_ssh_cmd = NULL;
static char *_ssh_cmd = NULL;

static char *_remote_push_options_result = NULL;

static int cred_acquire_cb(git_credential **, const char *, const char *, unsigned int, void *);

static git_remote *_remote;
Expand Down Expand Up @@ -373,7 +373,7 @@ void test_online_push__initialize(void)
_remote_ssh_passphrase = cl_getenv("GITTEST_REMOTE_SSH_PASSPHRASE");
_remote_default = cl_getenv("GITTEST_REMOTE_DEFAULT");
_remote_expectcontinue = cl_getenv("GITTEST_REMOTE_EXPECTCONTINUE");
_remote_push_options_result = cl_getenv("GITTEST_PUSH_OPTION_RESULT");
_remote_push_options = cl_getenv("GITTEST_PUSH_OPTIONS");
_remote = NULL;

_orig_ssh_cmd = cl_getenv("GIT_SSH");
Expand Down Expand Up @@ -437,7 +437,7 @@ void test_online_push__cleanup(void)
git__free(_remote_ssh_passphrase);
git__free(_remote_default);
git__free(_remote_expectcontinue);
git__free(_remote_push_options_result);
git__free(_remote_push_options);

git__free(_orig_ssh_cmd);
git__free(_ssh_cmd);
Expand All @@ -449,6 +449,7 @@ void test_online_push__cleanup(void)

record_callbacks_data_clear(&_record_cbs_data);

cl_fixture_cleanup("push-options-result");
cl_fixture_cleanup("testrepo.git");
cl_git_sandbox_cleanup();
}
Expand Down Expand Up @@ -827,30 +828,41 @@ void test_online_push__force(void)
NULL);
}

static void push_option_test(git_strarray push_options, const char *expected_option)
static void push_option_test(git_strarray given_options, const char *expected_option)
{
const char *specs[] = { "refs/heads/b1:refs/heads/b1" };
push_status exp_stats[] = { { "refs/heads/b1", 1 } };
expected_ref exp_refs[] = { { "refs/heads/b1", &_oid_b1 } };
git_str push_options_path = GIT_STR_INIT;
git_str push_options_result = GIT_STR_INIT;
char *options[16];
git_strarray push_options = { options, given_options.count + 1 };
size_t i;

/* Skip the test if we're missing the push options result file */
if (!_remote_push_options_result)
if (!_remote_push_options)
cl_skip();

cl_assert(given_options.count < 16);

cl_git_pass(git_str_joinpath(&push_options_path, clar_sandbox_path(), "push-options-result"));

options[0] = push_options_path.ptr;
for (i = 0; i < given_options.count; i++)
options[i + 1] = given_options.strings[i];

do_push(specs, ARRAY_SIZE(specs),
exp_stats, ARRAY_SIZE(exp_stats),
exp_refs, ARRAY_SIZE(exp_refs),
0, 1, 1,
&push_options);

if (git_futils_readbuffer(&push_options_result, _remote_push_options_result) < 0)
cl_fail("Failed to read push options result file");

cl_assert_equal_strn(expected_option, git_str_cstr(&push_options_result),
strlen(expected_option));
cl_assert(git_fs_path_exists(push_options_path.ptr));
cl_git_pass(git_futils_readbuffer(&push_options_result, push_options_path.ptr));

cl_assert_equal_s(expected_option, git_str_cstr(&push_options_result));
git_str_dispose(&push_options_result);
git_str_dispose(&push_options_path);
}

void test_online_push__options(void)
Expand Down
1 change: 1 addition & 0 deletions tests/resources/pushoptions.git/HEAD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ref: refs/heads/main
Empty file.
8 changes: 8 additions & 0 deletions tests/resources/pushoptions.git/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[core]
repositoryformatversion = 0
filemode = true
bare = true
ignorecase = true
precomposeunicode = true
[receive]
advertisePushOptions = true
1 change: 1 addition & 0 deletions tests/resources/pushoptions.git/description
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Unnamed repository; edit this file 'description' to name the repository.
3 changes: 3 additions & 0 deletions tests/resources/pushoptions.git/hooks/pre-receive
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
printf "${GIT_PUSH_OPTION_1}${GIT_PUSH_OPTION_2}${GIT_PUSH_OPTION_3}" > "${GIT_PUSH_OPTION_0}"
exit 0
6 changes: 6 additions & 0 deletions tests/resources/pushoptions.git/info/exclude
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
Empty file.
Empty file.
Empty file.
Empty file.
0