git:https-and-ssh: Fix ssh -> https

Apparently there was an issue with the conversion from ssh to https
which I never noticed? The script would replace the colon of the
`https://` and not the one after the domain:

    https///github.com:[...]

I rewrote both cases in a simpler way while fixing the issue.
This commit is contained in:
2025-01-21 18:01:51 +01:00
parent 83a1b0bc18
commit 149643a31f

View File

@@ -9,12 +9,12 @@ remote="${1:-origin}"
url="$($GIT remote get-url "$remote")"
if [ "${url##https://}" = "$url" ]; then
https_url="https://${url##*@}"
https_url="${https_url%%:*}/${https_url#*:}"
https_url="${url##*@}"
https_url="https://${https_url/:/\/}"
$GIT remote set-url "$remote" "$https_url"
$GIT remote set-url --push "$remote" "$url"
else
ssh_url="git@${url#https://}"
ssh_url="${ssh_url%%/*}:${ssh_url#*/}"
ssh_url="${url#https://}"
ssh_url="git@${ssh_url/\//:}"
$GIT remote set-url --push "$remote" "$ssh_url"
fi