diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2016-11-08 16:08:17 -0200 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2016-11-08 16:08:17 -0200 |
commit | 8bb9afefbd3f4ec5aa66383212e856977ec246f5 (patch) | |
tree | 6e0027d666bb568e7b4b58dfe2ddd542e3f670bb /share | |
parent | 2d3a2cd3d01e43c6e3c1a6eebad26bdf2a422d5a (diff) | |
download | hydra-8bb9afefbd3f4ec5aa66383212e856977ec246f5.tar.gz hydra-8bb9afefbd3f4ec5aa66383212e856977ec246f5.tar.bz2 |
Refactor sync-media-remotes
Diffstat (limited to 'share')
-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 |