#!/bin/bash
# 
# Acts like git push, but performs the action on the super-repo
# and each submodule, recursively.
# NCS, Nov 2017

[ -z "$1" ] && { echo "ERROR: You MUST provide the target remote (origin?) as the first argument" ; exit 1 ; }
[ -z "$2" ] && { echo "ERROR: You MUST provide the target branch to push as the second argument" ; exit 1 ; }

printf "Doing:\n\t git push $1 $2 \n\n"

# Verify that we are in the super-repo
[ -d CanAM ] ||  { echo "ERROR: You MUST be in the CanESM super-repo" ; exit 1 ; }

# Checkout the target branch
git submodule foreach --recursive "git push  $1 $2 || :"
git push $1 $2 || { echo "WARNING: Problem in merging the super-repo" ; }
 
