#!/bin/bash
# Test anonymous push with a custom branch
# nm = non-master
C=`pwd`
P="hook_update_anon_nm"
rm -rf ${P}_*.git
mkdir ${P}_dest.git
(
cd ${P}_dest.git
git init --bare
)
cp ../hooks/* ${P}_dest.git/hooks/
git clone ${P}_dest.git ${P}_src.git
cd ${P}_src.git
export ROCKETGIT_REPO_ID=2000000001
export ROCKETGIT_IP="IP"
export GIT_NAMESPACE="abcdefgh" # we have to set it manually
export ROCKETGIT_MR_QUEUE="${C}/mr_queue"
rm -f ../mr_queue/mr-${ROCKETGIT_REPO_ID}-*
echo "=== Preparing repo..."
echo "bbb" > a
git add a
git commit -m "b" a
echo "*** Creating a branch..."
export ROCKETGIT_REPO_RIGHTS="CP"
git checkout -b branch1
git push origin branch1
echo "=== Testing anon push without rights..."
export ROCKETGIT_REPO_RIGHTS=""
git push origin master
if [ "${?}" = "0" ]; then
echo "Should not work!"
exit 1
fi
set -e
echo "=== Testing anon push with rights..."
export ROCKETGIT_REPO_RIGHTS="H"
git push origin master
if [ "${?}" != "0" ]; then
echo "Should work!"
exit 1
fi
# Test if the namespace was updated instead of main namespace
diff ../${P}_dest.git/refs/namespaces/${GIT_NAMESPACE}/refs/heads/master \
.git/refs/heads/master
if [ "${?}" != "0" ]; then
echo "We did not update the namespace!"
exit 1
fi
if [ -r ../${P}_dest.git/refs/heads/master ]; then
echo "Seems we updated also main namespace!"
exit 1
fi
if [ "`ls ../mr_queue/mr-${ROCKETGIT_REPO_ID}-*`" = "" ]; then
echo "Seems that the merge queue file was not created!"
exit 1
fi
# TODO: we should not allow force pushes on anon branches
cd ..
rm -rf ${P}_*.git
echo "hook_update_anon_nm: OK!"
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"
Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/rocketgit
Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/rocketgit
You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a
pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master