#!/bin/bash

remote=${1:-origin}

git rev-parse --show-toplevel || { echo "can't get repository" >&2; exit 1; }
git remote | grep -q $remote || { echo "no such remote" >&2; exit 1; }
echo "Existing 'push' attribs:"
if git config --get-all remote.$remote.push; then
    echo "Some existing push attribs found. Bailing."
    echo "would have done:"
    echo git config --add remote.$remote.push '"+refs/heads/wip/*:refs/heads/wip/*"'
    echo git config --add remote.$remote.push '"+refs/heads/snap/*:refs/heads/snap/*"'
    echo git config --add remote.$remote.push '"refs/heads/*:refs/heads/*"'
    exit 1
else
    echo "none"
    set -e
    git config --add remote.$remote.push '+refs/heads/wip/*:refs/heads/wip/*'
    git config --add remote.$remote.push '+refs/heads/snap/*:refs/heads/snap/*'
    git config --add remote.$remote.push 'refs/heads/*:refs/heads/*'
    echo "Done"
fi

