#!/bin/bash

# DESCRIPTION:
#
# Get branch fetch url (with origin url as a fallback).

function git_branch_remote_url {
    git -C "$GIT_ROOT" config --get remote."$(git -C "$GIT_ROOT" config --get branch."$GIT_BRANCH".remote)".url
}

url="$(git_branch_remote_url)"

if [ -z "$url" ]; then
    url="$(git -C "$GIT_ROOT" config --get remote.origin.url)"
fi

if [ -n "$url" ]; then
    echo "$url"
fi
