summary refs log tree commit diff
path: root/pkgs/build-support/fetchgit
diff options
context:
space:
mode:
authortaku0 <taku0@users.noreply.github.com>2021-02-20 15:22:57 +0900
committerGitHub <noreply@github.com>2021-02-20 15:22:57 +0900
commita964d7094a30316f0f25dbe6dad5fb8b1878f57c (patch)
treea8f206cc1c2aa188495dd3bafa65c2c76c1ca75a /pkgs/build-support/fetchgit
parent0253d3097dfe4bb4a714d81b080a4248ea00da64 (diff)
parent6779902b32a208f39ab5d073714a12a7ac72bcf1 (diff)
downloadnixpkgs-a964d7094a30316f0f25dbe6dad5fb8b1878f57c.tar
nixpkgs-a964d7094a30316f0f25dbe6dad5fb8b1878f57c.tar.gz
nixpkgs-a964d7094a30316f0f25dbe6dad5fb8b1878f57c.tar.bz2
nixpkgs-a964d7094a30316f0f25dbe6dad5fb8b1878f57c.tar.lz
nixpkgs-a964d7094a30316f0f25dbe6dad5fb8b1878f57c.tar.xz
nixpkgs-a964d7094a30316f0f25dbe6dad5fb8b1878f57c.tar.zst
nixpkgs-a964d7094a30316f0f25dbe6dad5fb8b1878f57c.zip
Merge pull request #104714 from codedownio/tree-hashes
 fetchgit: support passing tree hashes as "rev" 
Diffstat (limited to 'pkgs/build-support/fetchgit')
-rwxr-xr-xpkgs/build-support/fetchgit/nix-prefetch-git14
1 files changed, 13 insertions, 1 deletions
diff --git a/pkgs/build-support/fetchgit/nix-prefetch-git b/pkgs/build-support/fetchgit/nix-prefetch-git
index a2dad2f698c..f2df9d9a869 100755
--- a/pkgs/build-support/fetchgit/nix-prefetch-git
+++ b/pkgs/build-support/fetchgit/nix-prefetch-git
@@ -149,7 +149,19 @@ checkout_hash(){
     fi
 
     clean_git fetch -t ${builder:+--progress} origin || return 1
-    clean_git checkout -b "$branchName" "$hash" || return 1
+
+    local object_type=$(git cat-file -t "$hash")
+    if [[ "$object_type" == "commit" ]]; then
+        clean_git checkout -b "$branchName" "$hash" || return 1
+    elif [[ "$object_type" == "tree" ]]; then
+        clean_git config user.email "nix-prefetch-git@localhost"
+        clean_git config user.name "nix-prefetch-git"
+        local commit_id=$(git commit-tree "$hash" -m "Commit created from tree hash $hash")
+        clean_git checkout -b "$branchName" "$commit_id" || return 1
+    else
+        echo "Unrecognized git object type: $object_type"
+        return 1
+    fi
 }
 
 # Fetch only a branch/tag and checkout it.