diff options
author | typebrook <typebrook@gmail.com> | 2020-04-28 11:11:19 +0800 |
---|---|---|
committer | typebrook <typebrook@gmail.com> | 2020-04-28 11:11:19 +0800 |
commit | 75992172bfecf78bf78b2a6a6ab4f6361a2df33a (patch) | |
tree | 0d18896d030aac89b0e4cb36d2f94e6129a1e81a /tools/swap-protocol.sh | |
parent | 9d6b7201c9b3277e6840ef873dba651d5c3e9011 (diff) |
update
Diffstat (limited to 'tools/swap-protocol.sh')
-rwxr-xr-x | tools/swap-protocol.sh | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tools/swap-protocol.sh b/tools/swap-protocol.sh new file mode 100755 index 0000000..03594f8 --- /dev/null +++ b/tools/swap-protocol.sh | |||
@@ -0,0 +1,16 @@ | |||
1 | #! /usr/bin/env bash | ||
2 | |||
3 | target='' | ||
4 | extra='' | ||
5 | |||
6 | git remote -v \ | ||
7 | | while read remote url etc; do | ||
8 | [[ $etc =~ push ]] && extra='--push' | ||
9 | if [[ -z $target || $target == https ]] && [[ $url =~ git@.*github.com ]]; then | ||
10 | target=${target:-https} | ||
11 | sed -E 's#git@(.+):(.+)#https://\1/\2#' <<<$url | xargs git remote set-url $extra $remote | ||
12 | elif [[ -z $target || $target == git ]] && [[ $url =~ https://.*github.com ]]; then | ||
13 | target=${target:-git} | ||
14 | sed -E 's#https://([^/]+)/(.+)#git@\1:\2#' <<<$url | xargs git remote set-url $extra $remote | ||
15 | fi | ||
16 | done | ||