git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: clime <clime7@gmail.com>
To: git@vger.kernel.org
Subject: getting pull/push/fetch url
Date: Fri, 17 May 2019 09:30:23 +0200	[thread overview]
Message-ID: <CAGqZTUvTg5S_-i9JjOwEG75CY+xFXJHAwTqh8uLG3SQTa3O0YA@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1036 bytes --]

Hello,

for my app, i need to be able get remote urls (fetch/pull/push) so
that i can derive some information from those, e.g. pull url netloc
from which i derive where other custom endpoints (binary file storage)
related to the remote git repo is located. This is just one example. I
am also using fetch url to store it into the composed package that i
generate by the app.

...And I also want to support git down to 1.7.1 (maybe i could live
with 1.8.3, not sure now)

Now, the problem is that getting those urls (fetch/pull/push) doesn't
seem to be an easy task. Currently i have the attached scripts to do
that. But i noticed that older gits like 1.7 use origin as a fallback
for pull url whereas the newer raise an error.

My question is if there is a better way to determine the urls that
would be backward compatible and easier than what i am doing right
now.

I could probably tweak my app to only use fetch url but then i won't
support triangle workflow so i would like to know if there is some
better option.

Thank you
clime

[-- Attachment #2: git_push_url --]
[-- Type: application/octet-stream, Size: 883 bytes --]

#!/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

[-- Attachment #3: git_pull_url --]
[-- Type: application/octet-stream, Size: 276 bytes --]

#!/bin/bash

# DESCRIPTION:
#
# Get branch pull url.

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 [ -n "$url" ]; then
    echo "$url"
fi

[-- Attachment #4: git_fetch_url --]
[-- Type: application/octet-stream, Size: 399 bytes --]

#!/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

             reply	other threads:[~2019-05-17  7:30 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-17  7:30 clime [this message]
2019-05-17  8:09 ` getting pull/push/fetch url Eric Sunshine
2019-05-17 11:02   ` clime
2019-05-17 11:10     ` clime

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAGqZTUvTg5S_-i9JjOwEG75CY+xFXJHAwTqh8uLG3SQTa3O0YA@mail.gmail.com \
    --to=clime7@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).