1#!/bin/env bash
2
3OLD_DOMAIN="git.ficd.sh"
4NEW_DOMAIN="g0.ficd.sh"
5PORT="59681"
6SEARCH_DIR="${1:-$PWD}"
7
8find "$SEARCH_DIR" -type d -name ".git" | while read -r gitdir; do
9 repo_dir="$(dirname "$gitdir")"
10 cd "$repo_dir" || exit 1
11 if ! git rev-parse --is-inside-work-tree &>/dev/null; then
12 continue
13 fi
14 # get current url
15 current_url=$(git remote get-url origin)
16 # match scp style
17 if [[ "$current_url" =~ ^git@${OLD_DOMAIN}:(.*) ]]; then
18 path="${BASH_REMATCH[1]}"
19 new_url="ssh://git@${NEW_DOMAIN}:${PORT}/${path}"
20 # match ssh://
21 elif [[ "$current_url" =~ ^ssh://git@${OLD_DOMAIN}(:[0-9]+)?/(.*) ]]; then
22 path="${BASH_REMATCH[2]}"
23 new_url="ssh://git@${NEW_DOMAIN}:${PORT}/${path}"
24 else
25 continue
26 fi
27 echo "Updating $repo_dir"
28 echo " Old: $current_url"
29 echo " New: $new_url"
30 git remote set-url origin "$new_url"
31done