From 6d9654a0253ce2f02ed5dd9e8fd6fa78918a42eb Mon Sep 17 00:00:00 2001 From: Pedro Algarvio Date: Tue, 29 Jul 2014 13:11:35 +0100 Subject: [PATCH] Attempt to initially shallow clone Salt's repository Fixes #435. Added extra logging information on the several git steps being taken while cloning the repository. --- bootstrap-salt.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/bootstrap-salt.sh b/bootstrap-salt.sh index d50a073..15f94ab 100755 --- a/bootstrap-salt.sh +++ b/bootstrap-salt.sh @@ -1110,19 +1110,26 @@ __git_clone_and_checkout() { [ -d /tmp/git ] || mkdir /tmp/git cd /tmp/git if [ -d $SALT_GIT_CHECKOUT_DIR ]; then + echodebug "Found a checked out Salt repository" cd $SALT_GIT_CHECKOUT_DIR + echodebug "Fetching git changes" git fetch || return 1 # Tags are needed because of salt's versioning, also fetch that + echodebug "Fetching git tags" git fetch --tags || return 1 # If we have the SaltStack remote set as upstream, we also need to fetch the tags from there if [ "$(git remote -v | grep $_SALTSTACK_REPO_URL)" != "" ]; then + echodebug "Fetching upstream(SaltStack's Salt repository) git tags" git fetch --tags upstream else + echoinfo "Adding SaltStack's Salt repository as a remote" git remote add upstream "$_SALTSTACK_REPO_URL" + echodebug "Fetching upstream(SaltStack's Salt repository) git tags" git fetch --tags upstream fi + echodebug "Hard reseting the cloned repository to ${GIT_REV}" git reset --hard "$GIT_REV" || return 1 # Just calling `git reset --hard $GIT_REV` on a branch name that has @@ -1132,21 +1139,37 @@ __git_clone_and_checkout() { # changes. git branch -a | grep -q "${GIT_REV}" if [ $? -eq 0 ]; then + echodebug "Rebasing the cloned repository branch" git pull --rebase || return 1 fi else + # Let's try shallow cloning to speed up + echoinfo "Attempting to shallow clone Salt's repository from ${_SALT_REPO_URL}" + git clone --depth 1 --branch "$GIT_REV" "$_SALT_REPO_URL" + if [ $? -eq 0 ]; then + cd "$SALT_GIT_CHECKOUT_DIR" + return 0 + fi + + # Shallow clone above failed(missing upstream tags???), let's resume the old behaviour. + echowarn "Failed to shallow clone." + echoinfo "Resuming regular git clone and remote SaltStack repository addition procedure" git clone "$_SALT_REPO_URL" || return 1 cd "$SALT_GIT_CHECKOUT_DIR" if [ "$_SALT_REPO_URL" != "$_SALTSTACK_REPO_URL" ]; then # We need to add the saltstack repository as a remote and fetch tags for proper versioning + echoinfo "Adding SaltStack's Salt repository as a remote" git remote add upstream "$_SALTSTACK_REPO_URL" + echodebug "Fetching upstream(SaltStack's Salt repository) git tags" git fetch --tags upstream fi + echodebug "Checking out $GIT_REV" git checkout "$GIT_REV" || return 1 fi + echoinfo "Cloning Salt's git repository succeeded" return 0 }