diff options
author | typebrook <typebrook@gmail.com> | 2020-05-04 09:59:50 +0800 |
---|---|---|
committer | typebrook <typebrook@gmail.com> | 2020-05-04 09:59:50 +0800 |
commit | a595e7c066c9b2700e5323f41f0a6af8eea68887 (patch) | |
tree | 242b012762389dd75b9e8440fb2f189037ff37fd | |
parent | ca9acdbd6757ab87530df0cddfca982fc57e7fcb (diff) |
update
-rwxr-xr-x | tools/swap-protocol.bash | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/tools/swap-protocol.bash b/tools/swap-protocol.bash index 91be977..00b6b4e 100755 --- a/tools/swap-protocol.bash +++ b/tools/swap-protocol.bash | |||
@@ -1,4 +1,6 @@ | |||
1 | #! /usr/bin/env bash | 1 | #! /usr/bin/env bash |
2 | # Get the first remote URL within git/https protocol on github.com | ||
3 | # Swap the protocol, and apply new protocol to every remaining remotes | ||
2 | 4 | ||
3 | target='' | 5 | target='' |
4 | extra='' | 6 | extra='' |
@@ -6,7 +8,9 @@ extra='' | |||
6 | # For each remote | 8 | # For each remote |
7 | git remote -v \ | 9 | git remote -v \ |
8 | | while read remote url etc; do | 10 | | while read remote url etc; do |
11 | # Set fetch/push URL seperately | ||
9 | [[ $etc =~ push ]] && extra='--push' || extra='' | 12 | [[ $etc =~ push ]] && extra='--push' || extra='' |
13 | |||
10 | if [[ $url =~ git@.*github.com ]]; then | 14 | if [[ $url =~ git@.*github.com ]]; then |
11 | target=${target:-https} | 15 | target=${target:-https} |
12 | [[ $target == https ]] && sed -E 's#^git@(.+):(.+)$#https://\1/\2#' <<<$url | xargs git remote set-url $extra $remote | 16 | [[ $target == https ]] && sed -E 's#^git@(.+):(.+)$#https://\1/\2#' <<<$url | xargs git remote set-url $extra $remote |