Added working version of git hook clone-or-pull
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
This commit is contained in:
parent
2942760a41
commit
e8adba0332
2 changed files with 20 additions and 10 deletions
7
README.adoc
Normal file
7
README.adoc
Normal 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.
|
||||||
|
|
@ -2,27 +2,30 @@
|
||||||
|
|
||||||
# FIXME: Add checks
|
# FIXME: Add checks
|
||||||
# FIXME: Add logging
|
# FIXME: Add logging
|
||||||
REPO=$(realpath "$PWD");
|
REPO=$(realpath "$GIT_DIR");
|
||||||
TARGET_DIR="$1";
|
TARGET_DIR="$1";
|
||||||
BRANCH="$2";
|
BRANCH="$2";
|
||||||
|
|
||||||
env
|
unset GIT_DIR
|
||||||
|
unset GIT_PUSH_OPTION_COUNT
|
||||||
|
|
||||||
function perform_clone_or_pull {
|
function perform_clone_or_pull {
|
||||||
target="$1";
|
target="$1";
|
||||||
echo "Checking out working copy to remote: $target"
|
echo "Checking out working copy to remote: $target"
|
||||||
if [ ! -e "$target/.git" ]; then
|
if [ ! -e "$target/.git" ]; then
|
||||||
git clone "$REPO" "$target";
|
git clone "$REPO" "$target"
|
||||||
fi
|
fi
|
||||||
(
|
|
||||||
cd "$target";
|
cd "$target"
|
||||||
echo "Working directory: $target"
|
echo -n "Working directory: "
|
||||||
git fetch
|
pwd
|
||||||
git checkout origin/$BRANCH
|
git fetch &> /dev/null
|
||||||
)
|
echo "Checking out branch $BRANCH"
|
||||||
echo "Working copy checked out";
|
git checkout "origin/$BRANCH"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
while read old_rew new_rew ref; do
|
while read old_rew new_rew ref; do
|
||||||
if [ "$ref" == "refs/heads/$BRANCH" ]; then
|
if [ "$ref" == "refs/heads/$BRANCH" ]; then
|
||||||
perform_clone_or_pull "$TARGET_DIR";
|
perform_clone_or_pull "$TARGET_DIR";
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue