#!/bin/bash

if [ "$1" == "--help" ]; then
  echo "USAGE: $0"
  echo "    This command takes no arguments."
  echo ""
  echo "This script does a git submodule update on all submodules"
  exit 0
fi

function has_upstream() {
  git rev-parse @{u} > /dev/null 2>&1
}

set -x -e

$(dirname $0)/install-git-hooks

has_upstream && git pull

if [[ "$(git --version | grep 'version 1.7')x" != "x" ]]; then
  git submodule foreach --recursive git submodule sync && git submodule update --init --recursive
else
  git submodule sync --recursive && git submodule foreach --recursive git submodule sync  && git submodule update --init --recursive
fi

