#!/bin/bash

verbose=false
if [ "$1" = "-v" ]; then
    verbose=true
fi

set -eu

# Run this from the top-level vamp-build-and-test directory

cat METADATA/repos.txt | grep -v '^#' | awk -F= '{ print $1 }' |
    while read name; do
	( cd "$name"
	  if [ -d .hg ]; then
	      nchanged=$(hg st -dram | wc -l | awk '{ print $1; }')
	      phase=$(hg phase . | awk '{ print $2; }')
	      if [ "$nchanged" != "0" ]; then
		  if [ "$phase" != "public" ]; then
		      echo "$name: uncommitted, unpushed"
		  else
		      echo "$name: uncommitted"
		  fi
	      elif [ "$phase" != "public" ]; then
		  echo "$name: unpushed"
	      elif [ "$verbose" = "true" ]; then
		  echo "$name: ok"
	      fi
	  elif [ -d .git ]; then
	      changes=$(git diff --numstat)
	      if [ "$changes" != "" ]; then
		  echo "$name: changed"
	      elif [ "$verbose" = "true" ]; then
		  echo "$name: ok"
	      fi
	  fi
	)
    done
