diff options
| author | Hsieh Chin Fan <typebrook@gmail.com> | 2020-08-28 10:19:25 +0800 |
|---|---|---|
| committer | Hsieh Chin Fan <typebrook@gmail.com> | 2020-08-28 10:19:25 +0800 |
| commit | c2c497544e005239411896632b592901e4fc475a (patch) | |
| tree | bffe344ed519f09d6c095cf4b49d0d7a6c03fbe9 /tools/git | |
| parent | 70abb62283f1a224f8c194323b8c2056561bf354 (diff) | |
update
Diffstat (limited to 'tools/git')
| -rwxr-xr-x | tools/git/swap-protocol.bash | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/tools/git/swap-protocol.bash b/tools/git/swap-protocol.bash new file mode 100755 index 0000000..b7f4db2 --- /dev/null +++ b/tools/git/swap-protocol.bash | |||
| @@ -0,0 +1,25 @@ | |||
| 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 | ||
| 4 | |||
| 5 | target='' | ||
| 6 | extra='' | ||
| 7 | |||
| 8 | # For each remote | ||
| 9 | git remote -v \ | ||
| 10 | | while read remote url etc; do | ||
| 11 | # Set fetch/push URL seperately | ||
| 12 | [[ $etc =~ push ]] && extra='--push' || extra='' | ||
| 13 | |||
| 14 | if [[ $url =~ git@.*github.com ]]; then | ||
| 15 | target=${target:-https} | ||
| 16 | # git@ -> https:// | ||
| 17 | [[ $target == https ]] && sed -E 's#^git@(.+):(.+)$#https://\1/\2#' <<<$url | xargs git remote set-url $extra $remote | ||
| 18 | elif [[ $url =~ https://.*github.com ]]; then | ||
| 19 | target=${target:-git} | ||
| 20 | # https:// -> git@ | ||
| 21 | [[ $target == git ]] && sed -E 's#^https://([^/]+)/(.+)$#git@\1:\2#' <<<$url | xargs git remote set-url $extra $remote | ||
| 22 | fi | ||
| 23 | done | ||
| 24 | |||
| 25 | git remote -v | ||