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 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";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue