Add proper exit code
[hvutilities.git] / scripts / git-project-update.sh
index 6fec40b..302a4f8 100755 (executable)
@@ -32,9 +32,12 @@ if [ ! -f ${SUBREPOS_LIST} ]; then
 fi
 
 branch=${1}
+rc=0
 
 update_repo()
 {
+    local valid="0"
+
     if [ ${#} -ne 1 ]; then
         echo "Missing repository name"
         exit 1
@@ -42,35 +45,30 @@ update_repo()
 
     local r=${1}
 
-    echo "Repo ${r}:"
+    echo -n "Repo ${r}: "
 
     pushd "${r}" 1> /dev/null
     b=${branch}
-    exists=$(git show-ref refs/heads/${b})
-
-    if [ -n "$exists" ]; then
-        [ -n "${debug}" ] && echo "branch <${b}> exists"
-        vco ${b} 1> /dev/null
-    else
-        echo "Branch <${b}> not found, trying <latest>"
-        b=latest
+
+    for b in ${branch} latest master; do
         exists=$(git show-ref refs/heads/${b})
         if [ -n "$exists" ]; then
-            [ -n "${debug}" ] && echo "branch <${b}> exists"
-            vco ${b} 1> /dev/null
-        else
-            echo "Branch <${b}> not found, defaulting to <master>"
-            b=master
-            exists=$(git show-ref refs/heads/${b})
-            if [ -n "$exists" ]; then
-                [ -n "${debug}" ] && echo "branch <${b}> exists"
-                vco ${b} 1> /dev/null
-            else
-                echo "Error swtiching to branch <${b}>"
-                exit 1
+            vco -q ${b} 1> /dev/null
+
+            if [ ${?} -ne 0 ]; then
+                rc=1
             fi
+            echo "${b}"
+            valid="1"
+            break
         fi
+    done
+
+    if [ x"${valid}" = x"0" ]; then
+        echo "No valid branch found"
+        rc=1
     fi
+
     popd 1> /dev/null
 }
 
@@ -95,3 +93,5 @@ while IFS=$'\n' read r ; do
 
     update_repo ${r}
 done < ${SUBREPOS_LIST}
+
+exit ${rc}