gitea-hooks/bin/clone-or-pull
Tony Tkacik 2942760a41 Added debug options.
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
2019-05-03 13:04:29 +02:00

30 lines
580 B
Bash
Executable file

#!/usr/bin/env bash
# FIXME: Add checks
# FIXME: Add logging
REPO=$(realpath "$PWD");
TARGET_DIR="$1";
BRANCH="$2";
env
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 "Working directory: $target"
git fetch
git checkout origin/$BRANCH
)
echo "Working copy checked out";
}
while read old_rew new_rew ref; do
if [ "$ref" == "refs/heads/$BRANCH" ]; then
perform_clone_or_pull "$TARGET_DIR";
fi;
done;