JBAS-415 eg-updator avoids extra git server lookup
authorBill Erickson <berickxx@gmail.com>
Mon, 26 Jan 2015 20:52:32 +0000 (12:52 -0800)
committerBill Erickson <berickxx@gmail.com>
Thu, 21 Mar 2019 19:46:23 +0000 (15:46 -0400)
Only call git fetch or pull once, so the user won't be
prompted for multiple SSH key logins when using keys/passwords.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
KCLS/misc-scripts/eg-updater.sh

index 64accc5..4408ffa 100755 (executable)
@@ -181,18 +181,21 @@ function checkout_code {
 
 function fetch_code {
 
-    # update local refs
-    $GIT fetch $GIT_REMOTE > /dev/null
-
     if [ -n "$GIT_PULL" ]; then
+        # 'git fetch' is unnecessary when pulling, plus it causes
+        # an extra password prompt when using SSH keys w/ passwords
         announce "Pulling updates for $($GIT rev-parse --abbrev-ref HEAD)";
         $GIT pull > /dev/null
 
     elif [ -n "$GIT_TAG" ]; then
+        announce "Fetching Git remote $GIT_REMOTE"
+        $GIT fetch $GIT_REMOTE > /dev/null
         announce "Checking out tag $GIT_TAG"
         checkout_code "$GIT_TAG" "$GIT_TAG"
 
     elif [ -n "$GIT_BRANCH" ]; then
+        announce "Fetching Git remote $GIT_REMOTE"
+        $GIT fetch $GIT_REMOTE > /dev/null
         announce "Checking out branch $GIT_BRANCH"
         checkout_code "$GIT_BRANCH" "$GIT_REMOTE/$GIT_BRANCH"