Simplify output of git-project-update.sh
authorHugo Villeneuve <hvilleneuve@addenergie.ca>
Tue, 16 Jan 2018 19:58:22 +0000 (14:58 -0500)
committerHugo Villeneuve <hvilleneuve@addenergie.ca>
Tue, 16 Jan 2018 19:58:22 +0000 (14:58 -0500)
scripts/git-project-update.sh

index 6fec40b..0a37cc1 100755 (executable)
@@ -35,6 +35,8 @@ branch=${1}
 
 update_repo()
 {
+    local valid="0"
+
     if [ ${#} -ne 1 ]; then
         echo "Missing repository name"
         exit 1
@@ -42,35 +44,25 @@ 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
-            fi
+            vco -q ${b} 1> /dev/null
+            echo "${b}"
+            valid="1"
+            break
         fi
+    done
+
+    if [ x"${valid}" = x"0" ]; then
+        echo "No valid branch found"
     fi
+
     popd 1> /dev/null
 }