git:https-and-ssh: Swap the if blocks

My brain assumes that the first block handles the case of the url being
an https one if I read http in the condition. Swap them and negate the
condition for better readability.

This might be a symptom of this condition being to complex, but well -
it's shell scripting ¯\_(ツ)_/¯
This commit is contained in:
2025-01-21 18:08:18 +01:00
parent 149643a31f
commit c6cdc6ec78

View File

@@ -8,13 +8,13 @@ GIT="git"
remote="${1:-origin}"
url="$($GIT remote get-url "$remote")"
if [ "${url##https://}" = "$url" ]; then
if [ "${url##https://}" != "$url" ]; then
ssh_url="${url#https://}"
ssh_url="git@${ssh_url/\//:}"
$GIT remote set-url --push "$remote" "$ssh_url"
else
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="${url#https://}"
ssh_url="git@${ssh_url/\//:}"
$GIT remote set-url --push "$remote" "$ssh_url"
fi