about summary refs log tree commit diff
path: root/pkgs/build-support/fetchgit/nix-prefetch-git
diff options
context:
space:
mode:
authorRicardo M. Correia <rcorreia@wizy.org>2015-04-20 14:25:14 +0200
committerRicardo M. Correia <rcorreia@wizy.org>2015-04-21 19:46:29 +0200
commitc55c7e1c1e09dfa57e1a44d08c777f995493d2c9 (patch)
tree9aa14e50e85c9bb9f08b4c2eac99d988a2afae3f /pkgs/build-support/fetchgit/nix-prefetch-git
parentb1b4092ad5d12ee17e934c35fdd84119fce060ad (diff)
downloadnixlib-c55c7e1c1e09dfa57e1a44d08c777f995493d2c9.tar
nixlib-c55c7e1c1e09dfa57e1a44d08c777f995493d2c9.tar.gz
nixlib-c55c7e1c1e09dfa57e1a44d08c777f995493d2c9.tar.bz2
nixlib-c55c7e1c1e09dfa57e1a44d08c777f995493d2c9.tar.lz
nixlib-c55c7e1c1e09dfa57e1a44d08c777f995493d2c9.tar.xz
nixlib-c55c7e1c1e09dfa57e1a44d08c777f995493d2c9.tar.zst
nixlib-c55c7e1c1e09dfa57e1a44d08c777f995493d2c9.zip
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`).
Diffstat (limited to 'pkgs/build-support/fetchgit/nix-prefetch-git')
-rwxr-xr-xpkgs/build-support/fetchgit/nix-prefetch-git12
1 files changed, 9 insertions, 3 deletions
diff --git a/pkgs/build-support/fetchgit/nix-prefetch-git b/pkgs/build-support/fetchgit/nix-prefetch-git
index 486fd3acafb7..b45ce81f8801 100755
--- a/pkgs/build-support/fetchgit/nix-prefetch-git
+++ b/pkgs/build-support/fetchgit/nix-prefetch-git
@@ -8,6 +8,7 @@ deepClone=$NIX_PREFETCH_GIT_DEEP_CLONE
 leaveDotGit=$NIX_PREFETCH_GIT_LEAVE_DOT_GIT
 fetchSubmodules=
 builder=
+branchName=$NIX_PREFETCH_GIT_BRANCH_NAME
 
 if test -n "$deepClone"; then
     deepClone=true
@@ -31,6 +32,7 @@ for arg; do
             --url) argfun=set_url;;
             --rev) argfun=set_rev;;
             --hash) argfun=set_hashType;;
+            --branch-name) argfun=set_branchName;;
             --deepClone) deepClone=true;;
             --no-deepClone) deepClone=false;;
             --leave-dotGit) leaveDotGit=true;;
@@ -108,7 +110,7 @@ checkout_hash(){
     fi
 
     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.
@@ -131,7 +133,7 @@ checkout_ref(){
     if test -n "$ref"; then
         # --depth option is ignored on http repository.
         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
         return 1
     fi
@@ -251,7 +253,7 @@ clone_user_rev() {
             fi;;
     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 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)"
@@ -268,6 +270,10 @@ clone_user_rev() {
     fi
 }
 
+if test -z "$branchName"; then
+    branchName=fetchgit
+fi
+
 if test -n "$builder"; then
     test -n "$out" -a -n "$url" -a -n "$rev" || usage
     mkdir $out