From ca9acdbd6757ab87530df0cddfca982fc57e7fcb Mon Sep 17 00:00:00 2001 From: typebrook Date: Mon, 4 May 2020 09:55:34 +0800 Subject: update --- tools/swap-protocol.bash | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'tools/swap-protocol.bash') diff --git a/tools/swap-protocol.bash b/tools/swap-protocol.bash index a70e7fe..91be977 100755 --- a/tools/swap-protocol.bash +++ b/tools/swap-protocol.bash @@ -3,15 +3,16 @@ target='' extra='' +# For each remote git remote -v \ | while read remote url etc; do - [[ $etc =~ push ]] && extra='--push' - if [[ -z $target || $target == https ]] && [[ $url =~ git@.*github.com ]]; then + [[ $etc =~ push ]] && extra='--push' || extra='' + if [[ $url =~ git@.*github.com ]]; then target=${target:-https} - sed -E 's#git@(.+):(.+)#https://\1/\2#' <<<$url | xargs git remote set-url $extra $remote - elif [[ -z $target || $target == git ]] && [[ $url =~ https://.*github.com ]]; then + [[ $target == https ]] && sed -E 's#^git@(.+):(.+)$#https://\1/\2#' <<<$url | xargs git remote set-url $extra $remote + elif [[ $url =~ https://.*github.com ]]; then target=${target:-git} - sed -E 's#https://([^/]+)/(.+)#git@\1:\2#' <<<$url | xargs git remote set-url $extra $remote + [[ $target == git ]] && sed -E 's#^https://([^/]+)/(.+)$#git@\1:\2#' <<<$url | xargs git remote set-url $extra $remote fi done -- cgit v1.2.3-70-g09d2