diff --git a/README.adoc b/README.adoc new file mode 100644 index 0000000..3afd26b --- /dev/null +++ b/README.adoc @@ -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. diff --git a/bin/clone-or-pull b/bin/clone-or-pull index 3b0638d..15d75df 100755 --- a/bin/clone-or-pull +++ b/bin/clone-or-pull @@ -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";