Commit 85e74134 authored by Jérome Perrin's avatar Jérome Perrin Committed by Kirill Smelkov

Make gowork-snapshot support repositories in detached head

When git repositories are in detached head, `git symbolic-ref` cannot be used.

In this case, `gowork-snapshot` outputs `fatal: ref origin is not a symbolic ref` and create a buildout profile with empty revisions.

After these changes, we try to get from a remote named origin in this case. If this did not work, we output the problematic repository.

I added some minor "cleanups" at the same time.

/reviewed-on !268
/reviewed-by kirr
parents 489c462d c54063e4
...@@ -25,9 +25,16 @@ gogit_list() { ...@@ -25,9 +25,16 @@ gogit_list() {
# git_upstream_url <repo> - show current branch upstream URL # git_upstream_url <repo> - show current branch upstream URL
git_upstream_url() { git_upstream_url() {
repo=$1 repo=$1
head="`git -C $repo symbolic-ref --short HEAD`" # current branch - e.g. "t" head="`git -C $repo symbolic-ref -q --short HEAD`" # current branch - e.g. "master"
remote="`git -C $repo config --get branch.$head.remote`" # upstream name, e.g. "kirr" if [ -z $head ] ; then
url="`git -C $repo config --get remote.$remote.url`" # upstream URL 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" echo "$url"
} }
...@@ -59,5 +66,5 @@ while read pkg url rev; do ...@@ -59,5 +66,5 @@ while read pkg url rev; do
echo "<= go-git-package" echo "<= go-git-package"
echo "go.importpath = $pkg" echo "go.importpath = $pkg"
echo "repository = $url" echo "repository = $url"
echo "revision = $rev" echo "revision = $rev"
done done
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