Util: Make sure to init/update submodules on checkout

The git_checkout() utility function must make sure that
any submodule available in the source tree gets properly
updated and initialized recursively by calling:
git submodule update --init --recursive when the option
"SYNC_ALL_SUBMODULES" is passed as last parameter

Signed-off-by: Antonio de Angelis <antonio.deangelis@arm.com>
Change-Id: I917e5c580e8a1891b190584bd1ae6a282d061884
diff --git a/utils/util_git.sh b/utils/util_git.sh
index 0c5d909..b7a775b 100644
--- a/utils/util_git.sh
+++ b/utils/util_git.sh
@@ -13,8 +13,8 @@
 
 function git_clone() {
     # Parse the repo elements
-    REPO_URL=$1
-    REPO_PATH=$2
+    local REPO_URL=$1
+    local REPO_PATH=$2
 
     # In case repository is not defined, just skip it
     if [ -z "${REPO_URL}" ]; then
@@ -29,8 +29,9 @@
 
 function git_checkout() {
     # Parse the repo elements
-    REPO_PATH=$1
-    REPO_REFSPEC=$2
+    local REPO_PATH=$1
+    local REPO_REFSPEC=$2
+    local SYNC_CMD=$3
 
     # Checkout if repo exits
     if [ -d ${REPO_PATH} ]; then
@@ -53,6 +54,11 @@
             git checkout ${REPO_REFSPEC}
         fi
 
+        if [ "${SYNC_CMD}" = "SYNC_ALL_SUBMODULES" ]; then
+            # Make sure that any submodule is also inited and updated if present
+            git submodule update --init --recursive
+        fi
+
         echo -e "Share Folder ${REPO_PATH} $(git rev-parse --short HEAD)\n"
         cd $OLDPWD
     fi