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 (52b30ceef29788b2c07e31db2f38b1f0ee3f6e81) (4,629B) (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_REPO_RIGHTS="CP"
#strace -o cata.strace -ff -s200 \
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_REPO_RIGHTS="COP"
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_REPO_RIGHTS="${ROCKETGIT_REPO_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_REPO_RIGHTS="${ROCKETGIT_REPO_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_REPO_RIGHTS="${ROCKETGIT_REPO_RIGHTS}u"
git push origin :refs/tags/tag1
if [ "${?}" != "0" ]; then
	echo "Should work!"
	exit 1
fi

echo "=== Testing merge-commit without rights (${ROCKETGIT_REPO_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 -m "x" branch1
git push
if [ "${?}" != "1" ]; then
	echo "Should not work!"
	exit 1
fi
echo "=== Testing merge-commit with rights..."
export ROCKETGIT_REPO_RIGHTS="${ROCKETGIT_REPO_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 bad-whitespace with rights..."
export ROCKETGIT_REPO_RIGHTS="${ROCKETGIT_REPO_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_REPO_RIGHTS="${ROCKETGIT_REPO_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_REPO_RIGHTS="${ROCKETGIT_REPO_RIGHTS}S"
git push origin --tags
if [ "${?}" != "0" ]; then
	echo "Should work!"
	exit 1
fi

echo "=== Testing annotated tag change without rights..."
echo "aaa" >> a; git commit -a -m "xx"
git tag -d tag2
git tag -a tag2 -m "xxx2"
git push origin --tags
if [ "${?}" != "1" ]; then
	echo "Should not work!"
	exit 1
fi
echo "=== Testing annotated tag change with rights..."
export ROCKETGIT_REPO_RIGHTS="${ROCKETGIT_REPO_RIGHTS}N"
git push origin --tags
if [ "${?}" != "0" ]; then
	echo "Should work!"
	exit 1
fi

echo "=== Testing annotated tag delete without rights (${ROCKETGIT_REPO_RIGHTS})..."
git tag -d tag2
git push origin :refs/tags/tag2
if [ "${?}" != "1" ]; then
	echo "Should not work!"
	exit 1
fi
echo "=== Testing annotated tag delete with rights..."
export ROCKETGIT_REPO_RIGHTS="${ROCKETGIT_REPO_RIGHTS}n"
git push origin :refs/tags/tag2
if [ "${?}" != "0" ]; then
	echo "Should work!"
	exit 1
fi


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

rm -rf hook_update_*.git

echo "hook_pre-update: 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