Commit dfef72bf authored by Jérome Perrin's avatar Jérome Perrin

gowork-snapshot: supports repositories in detached head

When git repository is in detached head, there's no symbolic-ref, so we
cannot anything better that assuming there's a remote named "origin"
parent 8f4f9c64
......@@ -25,9 +25,16 @@ gogit_list() {
# git_upstream_url <repo> - show current branch upstream URL
git_upstream_url() {
repo=$1
head="`git -C $repo symbolic-ref --short HEAD`" # current branch - e.g. "master"
remote="`git -C $repo config --get branch.$head.remote`" # upstream name, e.g. "origin"
url="`git -C $repo config --get remote.$remote.url`" # upstream URL
head="`git -C $repo symbolic-ref -q --short HEAD`" # current branch - e.g. "master"
if [ -z $head ] ; then
remote="origin" # If we are in detached HEAD, assume the upstream name is origin
else
remote="`git -C $repo config --get branch.$head.remote`" # upstream name, e.g. "origin"
fi
url="`git -C $repo config --get remote.$remote.url`" # upstream URL
if [ -z $url ] ; then
echo "ERROR: Failed to guess upstream url from $repo" 1>&2
fi
echo "$url"
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment