diff options
Diffstat (limited to 'share/hydractl')
-rwxr-xr-x | share/hydractl/sync-media-remotes | 54 |
1 files changed, 32 insertions, 22 deletions
diff --git a/share/hydractl/sync-media-remotes b/share/hydractl/sync-media-remotes index fd69708..1b8f59e 100755 --- a/share/hydractl/sync-media-remotes +++ b/share/hydractl/sync-media-remotes @@ -17,35 +17,45 @@ elif [ ! -d "$DEST/$MEDIA" ]; then exit 1 fi -# TODO -echo "Needs work!" -exit - # Run for folder in `ls $MEDIA`; do if [ -d "$DEST/$MEDIA/$folder/.git" ]; then - git -C $MEDIA/$folder remote -v | grep "(fetch)" | sed -e 's/(fetch)//' | while read remote; do - ( + # Add new remotes + git -C $MEDIA/$folder remote -v | while read remote; do cd $DEST/$MEDIA/$folder name="`echo $remote | cut -d ' ' -f 1`" - url="`echo $remote | cut -d ' ' -f 2`" - - # Add and update - if [ "$name" != "all" ]; then - if ! git remote | grep -q "^$name$" ]; then - git remote add $remote - else - oldurl="`git remote -v | grep "^$name$" | grep "(fetch)" | cut -d ' ' -f 2`" - - if [ "$url" != "$oldurl" ]; then - git remote set-url $name --delete $oldurl - git remote set-url $name --add $url - fi - fi + addr="`echo $remote | cut -d ' ' -f 2`" + type="`echo $remote | cut -d ' ' -f 3`" + + if [ "$type" == "(push)" ]; then + command="set-url --push" + else + command="add" + fi + + if ! git remote -v | sed -e 's/\t/ /g' | grep -q "^$name $addr $type$"; then + git remote $command $name $addr + fi + done + + # Delete old remotes + git -C $DEST/$MEDIA/$folder remote -v | while read remote; do + cd $MEDIA/$folder + name="`echo $remote | cut -d ' ' -f 1`" + addr="`echo $remote | cut -d ' ' -f 2`" + type="`echo $remote | cut -d ' ' -f 3`" + + if [ "$type" == "(push)" ]; then + command="set-url --delete" + arg="$addr" + else + command="remove" + arg="" fi - # Remove dangling remotes - ) + if ! git remote -v | sed -e 's/\t/ /g' | grep -q "^$name $addr $type$"; then + git -C $DEST/$MEDIA/$folder remote $command $name $arg + fi done fi done |