Added working version of git hook clone-or-pull

Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
This commit is contained in:
Tony Tkáčik 2019-05-03 13:05:57 +02:00
parent 2942760a41
commit e8adba0332
2 changed files with 20 additions and 10 deletions

7
README.adoc Normal file
View file

@ -0,0 +1,7 @@
## clone-or-pull
Clones repository if not present in target path, otherwises fetches changes.
Afterwards check-outs path.
The directory must be writeable by git user.

View file

@ -2,27 +2,30 @@
# FIXME: Add checks
# FIXME: Add logging
REPO=$(realpath "$PWD");
REPO=$(realpath "$GIT_DIR");
TARGET_DIR="$1";
BRANCH="$2";
env
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";
git clone "$REPO" "$target"
fi
(
cd "$target";
echo "Working directory: $target"
git fetch
git checkout origin/$BRANCH
)
echo "Working copy checked out";
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";