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.sh (36b13a1f7ae5b357256f18a56806a4a89bffd764) (3,676B) (mode 100755) [raw]
#!/bin/bash

rm -rf hook_update_*.git
mkdir hook_update_dest.git
(
cd hook_update_dest.git
git init --bare
)
cp ../hooks/update hook_update_dest.git/hooks/

git clone hook_update_dest.git hook_update_src.git

cd hook_update_src.git

echo "=== Testing push without rights..."
echo "aaa" > a
git add a
git commit -m "a" a
echo "bbb" >> a
git commit -m "b" a
git push origin master
if [ "${?}" != "1" ]; then
	echo "Should not work!"
	exit 1
fi
echo "=== Testing push with rights..."
export ROCKETGIT_RIGHTS="C"
git push origin master
if [ "${?}" != "0" ]; then
	echo "Should work!"
	exit 1
fi

echo "=== Testing not fast-forward without rights..."
git reset --hard HEAD~1
echo "bbb" > a
git commit -m "new a" a
git push --force origin master
if [ "${?}" != "1" ]; then
	echo "Should not work!"
	exit 1
fi
echo "=== Testing not fast-forward with rights..."
export ROCKETGIT_RIGHTS="${ROCKETGIT_RIGHTS}O"
cd hook_update_src.git
git push --force origin master
if [ "${?}" != "0" ]; then
	echo "Should work!"
	exit 1
fi

echo "=== Testing un-annotated tag creation without rights..."
git tag tag1
git push --tags origin
if [ "${?}" != "1" ]; then
	echo "Should not work!"
	exit 1
fi
echo "=== Testing un-annotated tag creation with rights..."
export ROCKETGIT_RIGHTS="${ROCKETGIT_RIGHTS}Y"
git push --tags origin
if [ "${?}" != "0" ]; then
	echo "Should work!"
	exit 1
fi

echo "=== Testing un-annotated tag modify without rights..."
git tag -d tag1
git tag tag1 HEAD~1
git push --force --tags origin
if [ "${?}" != "1" ]; then
	echo "Should not work!"
	exit 1
fi
echo "=== Testing un-annotated tag modify with rights..."
export ROCKETGIT_RIGHTS="${ROCKETGIT_RIGHTS}U"
git push --force --tags origin
if [ "${?}" != "0" ]; then
	echo "Should work!"
	exit 1
fi

echo "=== Testing un-annotated tag deletion without rights..."
git tag -d tag1
git push origin :refs/tags/tag1
if [ "${?}" != "1" ]; then
	echo "Should not work!"
	exit 1
fi
echo "=== Testing un-annotated tag deletion with rights..."
export ROCKETGIT_RIGHTS="${ROCKETGIT_RIGHTS}u"
git push origin :refs/tags/tag1
if [ "${?}" != "0" ]; then
	echo "Should work!"
	exit 1
fi

echo "=== Testing merge-commit without rights..."
git checkout -b branch1
echo "ccc" >> a
git commit -m "new b" a
git checkout master
echo "a" > b; git add b
git commit -m "c" b
git merge branch1
git push
if [ "${?}" != "1" ]; then
	echo "Should not work!"
	exit 1
fi
echo "=== Testing merge-commit with rights..."
export ROCKETGIT_RIGHTS="${ROCKETGIT_RIGHTS}M"
git push
if [ "${?}" != "0" ]; then
	echo "Should work!"
	exit 1
fi

echo "=== Testing bad-whitespace without rights..."
echo -e " \t \ta \t\n \r\n" > b
git commit -m "d" b
git push
if [ "${?}" != "1" ]; then
	echo "Should not work!"
	exit 1
fi
echo "=== Testing merge-commit with rights..."
export ROCKETGIT_RIGHTS="${ROCKETGIT_RIGHTS}W"
git push
if [ "${?}" != "0" ]; then
	echo "Should work!"
	exit 1
fi

echo "=== Testing branch delete without rights..."
git push origin branch1
git push origin :branch1
if [ "${?}" != "1" ]; then
	echo "Should not work!"
	exit 1
fi
echo "=== Testing branch delete with rights..."
export ROCKETGIT_RIGHTS="${ROCKETGIT_RIGHTS}D"
git push origin :branch1
if [ "${?}" != "0" ]; then
	echo "Should work!"
	exit 1
fi

echo "=== Testing annotated tag create without rights..."
git tag -a tag2 -m "xxx"
git push origin --tags
if [ "${?}" != "1" ]; then
	echo "Should not work!"
	exit 1
fi
echo "=== Testing annotated tag create with rights..."
export ROCKETGIT_RIGHTS="${ROCKETGIT_RIGHTS}S"
git push origin --tags
if [ "${?}" != "0" ]; then
	echo "Should work!"
	exit 1
fi


cd ..
echo "Rights=${ROCKETGIT_RIGHTS}."

rm -rf hook_update_*.git

echo "Done!"
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