#!/bin/bash

# DESCRIPTION:
#
# Get branch push url.

function git_branch_push_remote {
    branch_push_remote="$(git -C "$GIT_ROOT" config --get branch."$GIT_BRANCH".pushRemote)"

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

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

    echo "$branch_push_remote"
}

function git_branch_push_url {
    branch_push_remote="$(git_branch_push_remote)"

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

    echo "$push_url"
}

url="$(git_branch_push_url)"

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