gitea-hooks/bin/clone-or-pull
Tony Tkacik e8adba0332 Added working version of git hook clone-or-pull
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
2019-05-03 13:24:36 +02:00

33 lines
638 B
Bash
Executable file

#!/usr/bin/env bash
# FIXME: Add checks
# FIXME: Add logging
REPO=$(realpath "$GIT_DIR");
TARGET_DIR="$1";
BRANCH="$2";
unset GIT_DIR
unset GIT_PUSH_OPTION_COUNT
function perform_clone_or_pull {
target="$1";
echo "Checking out working copy to remote: $target"
if [ ! -e "$target/.git" ]; then
git clone "$REPO" "$target"
fi
cd "$target"
echo -n "Working directory: "
pwd
git fetch &> /dev/null
echo "Checking out branch $BRANCH"
git checkout "origin/$BRANCH"
}
while read old_rew new_rew ref; do
if [ "$ref" == "refs/heads/$BRANCH" ]; then
perform_clone_or_pull "$TARGET_DIR";
fi;
done;