fetchgit: Add support for specifying branch name
This is useful when `leaveDotGit = true` and some other derivation expects some branch name to exist. Previously, `nix-prefetch-git` always created a branch with a hard-coded name (`fetchgit`).
This commit is contained in:
parent
b1b4092ad5
commit
c55c7e1c1e
@ -9,6 +9,7 @@ header "exporting $url (rev $rev) into $out"
|
|||||||
$fetcher --builder --url "$url" --out "$out" --rev "$rev" \
|
$fetcher --builder --url "$url" --out "$out" --rev "$rev" \
|
||||||
${leaveDotGit:+--leave-dotGit} \
|
${leaveDotGit:+--leave-dotGit} \
|
||||||
${deepClone:+--deepClone} \
|
${deepClone:+--deepClone} \
|
||||||
${fetchSubmodules:+--fetch-submodules}
|
${fetchSubmodules:+--fetch-submodules} \
|
||||||
|
${branchName:+--branch-name "$branchName"}
|
||||||
|
|
||||||
stopNest
|
stopNest
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
in
|
in
|
||||||
{ url, rev ? "HEAD", md5 ? "", sha256 ? "", leaveDotGit ? deepClone
|
{ url, rev ? "HEAD", md5 ? "", sha256 ? "", leaveDotGit ? deepClone
|
||||||
, fetchSubmodules ? true, deepClone ? false
|
, fetchSubmodules ? true, deepClone ? false
|
||||||
|
, branchName ? null
|
||||||
, name ? urlToName url rev
|
, name ? urlToName url rev
|
||||||
}:
|
}:
|
||||||
|
|
||||||
@ -51,7 +52,7 @@ stdenv.mkDerivation {
|
|||||||
outputHashMode = "recursive";
|
outputHashMode = "recursive";
|
||||||
outputHash = if sha256 == "" then md5 else sha256;
|
outputHash = if sha256 == "" then md5 else sha256;
|
||||||
|
|
||||||
inherit url rev leaveDotGit fetchSubmodules deepClone;
|
inherit url rev leaveDotGit fetchSubmodules deepClone branchName;
|
||||||
|
|
||||||
GIT_SSL_CAINFO = "${cacert}/etc/ca-bundle.crt";
|
GIT_SSL_CAINFO = "${cacert}/etc/ca-bundle.crt";
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ deepClone=$NIX_PREFETCH_GIT_DEEP_CLONE
|
|||||||
leaveDotGit=$NIX_PREFETCH_GIT_LEAVE_DOT_GIT
|
leaveDotGit=$NIX_PREFETCH_GIT_LEAVE_DOT_GIT
|
||||||
fetchSubmodules=
|
fetchSubmodules=
|
||||||
builder=
|
builder=
|
||||||
|
branchName=$NIX_PREFETCH_GIT_BRANCH_NAME
|
||||||
|
|
||||||
if test -n "$deepClone"; then
|
if test -n "$deepClone"; then
|
||||||
deepClone=true
|
deepClone=true
|
||||||
@ -31,6 +32,7 @@ for arg; do
|
|||||||
--url) argfun=set_url;;
|
--url) argfun=set_url;;
|
||||||
--rev) argfun=set_rev;;
|
--rev) argfun=set_rev;;
|
||||||
--hash) argfun=set_hashType;;
|
--hash) argfun=set_hashType;;
|
||||||
|
--branch-name) argfun=set_branchName;;
|
||||||
--deepClone) deepClone=true;;
|
--deepClone) deepClone=true;;
|
||||||
--no-deepClone) deepClone=false;;
|
--no-deepClone) deepClone=false;;
|
||||||
--leave-dotGit) leaveDotGit=true;;
|
--leave-dotGit) leaveDotGit=true;;
|
||||||
@ -108,7 +110,7 @@ checkout_hash(){
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
git fetch ${builder:+--progress} origin || return 1
|
git fetch ${builder:+--progress} origin || return 1
|
||||||
git checkout -b fetchgit $hash || return 1
|
git checkout -b $branchName $hash || return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# Fetch only a branch/tag and checkout it.
|
# Fetch only a branch/tag and checkout it.
|
||||||
@ -131,7 +133,7 @@ checkout_ref(){
|
|||||||
if test -n "$ref"; then
|
if test -n "$ref"; then
|
||||||
# --depth option is ignored on http repository.
|
# --depth option is ignored on http repository.
|
||||||
git fetch ${builder:+--progress} --depth 1 origin +"$ref" || return 1
|
git fetch ${builder:+--progress} --depth 1 origin +"$ref" || return 1
|
||||||
git checkout -b fetchgit FETCH_HEAD || return 1
|
git checkout -b $branchName FETCH_HEAD || return 1
|
||||||
else
|
else
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
@ -251,7 +253,7 @@ clone_user_rev() {
|
|||||||
fi;;
|
fi;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
local full_revision=$(cd $dir && (git rev-parse $rev 2> /dev/null || git rev-parse refs/heads/fetchgit) | tail -n1)
|
local full_revision=$(cd $dir && (git rev-parse $rev 2> /dev/null || git rev-parse refs/heads/$branchName) | tail -n1)
|
||||||
echo "git revision is $full_revision"
|
echo "git revision is $full_revision"
|
||||||
echo "git human-readable version is $(cd $dir && (git describe $full_revision 2> /dev/null || git describe --tags $full_revision 2> /dev/null || echo -- none --))" >&2
|
echo "git human-readable version is $(cd $dir && (git describe $full_revision 2> /dev/null || git describe --tags $full_revision 2> /dev/null || echo -- none --))" >&2
|
||||||
echo "Commit date is $(cd $dir && git show --no-patch --pretty=%ci $full_revision)"
|
echo "Commit date is $(cd $dir && git show --no-patch --pretty=%ci $full_revision)"
|
||||||
@ -268,6 +270,10 @@ clone_user_rev() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if test -z "$branchName"; then
|
||||||
|
branchName=fetchgit
|
||||||
|
fi
|
||||||
|
|
||||||
if test -n "$builder"; then
|
if test -n "$builder"; then
|
||||||
test -n "$out" -a -n "$url" -a -n "$rev" || usage
|
test -n "$out" -a -n "$url" -a -n "$rev" || usage
|
||||||
mkdir $out
|
mkdir $out
|
||||||
|
Loading…
Reference in New Issue
Block a user