#!/bin/bash
set -e

lc="$(git rev-parse --git-dir)/stone"
rc=$(git config --get remote.origin.url|sed 's/\(git@.*:\).*\/\([^\/]*\)/\1\2\/stone/')

stone_args=$(git config --get remote.origin.url|sed 's/\(git@[^:]*\).*\/\([^\/]*\)/\1 stone \2/')
stones=$(ssh $stone_args)

cd $lc
for file in $(find -type f);do
    e=0
    for stone in $stones; do
        if [ $file == $stone ]; then
            e=1
            break
        fi
    done
    if [ $e -eq 0 ]; then
        scp -O $file $rc/$file
    fi
done
