xaizek / rocketgit (License: AGPLv3+) (since 2018-12-09)
Light and fast Git hosting solution suitable to serve both as a hub or as a personal code storage with its tickets, pull requests, API and much more.
<root> / tests / hook_update_anon.sh (f2a299c2b3a5594f246ec21a0a5eaf8d015323c5) (1,541B) (mode 100755) [raw]
#!/bin/bash

# Test anonymous push

C=`pwd`

rm -rf hook_update_anon_*.git
mkdir hook_update_anon_dest.git
(
cd hook_update_anon_dest.git
git init --bare
)
cp ../hooks/* hook_update_anon_dest.git/hooks/

git clone hook_update_anon_dest.git hook_update_anon_src.git

cd hook_update_anon_src.git

export ROCKETGIT_REPO_ID=2000000000
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 "=== 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 ../hook_update_anon_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 ../hook_update_anon_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 hook_update_anon_*.git

echo "hook_update_anon: OK!"
Hints

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