fetchgit builder rewrite to handle more cases

The old builder failed for:
- remote HEAD != master
- local repositories

svn path=/nixpkgs/trunk/; revision=26984
This commit is contained in:
Florian Friesdorf 2011-04-27 03:00:47 +00:00
parent ead24cacdf
commit a8c3649dd4

View File

@ -2,19 +2,22 @@ source $stdenv/setup
header "exporting $url (rev $rev) into $out" header "exporting $url (rev $rev) into $out"
git clone "$url" $out git init $out
cd $out
git remote add origin "$url"
git fetch origin
git remote set-head origin -a
# If no revision was specified, the remote HEAD will be used
git checkout -b __nixos_build__ origin/HEAD
if test -n "$rev"; then if test -n "$rev"; then
cd $out echo "Trying to checkout: $rev"
parsed_rev=$(
# Track all remote branches so that revisions like git rev-parse --verify "$rev" 2>/dev/null ||
# `t/foo@{2010-05-12}' are correctly resolved. Failing to do that, git rev-parse --verify origin/"$rev" 2>/dev/null
# Git bails out with an "invalid reference" error. )
for branch in $(git branch -rl | grep -v ' origin/master$') git reset --hard $parsed_rev
do
git branch --track "$(echo $branch | sed -es,origin/,,g)" "$branch"
done
git checkout "$rev" --
fi fi
if test -z "$leaveDotGit"; then if test -z "$leaveDotGit"; then