#!/bin/bash

wd="$(pwd)"
temp="$(mktemp)"
name="$(basename "$0")"

find /data -name '.git' -exec dirname \{\} \; | while read gitrepo; do
    cd "$gitrepo"
    case "$name" in
        "gitfetcher")
            echo "$gitrepo"
            git remote | while read remote; do
                git fetch --prune "$remote"
            done 2>&1 | sed 's/^/    /'
            ;;
        "gitlister")
            if git status | grep -q behind; then
                echo "$gitrepo"
            fi
            ;;
    esac
done

cd "$wd"