summaryrefslogtreecommitdiffstats
path: root/pkgs/build-support/fetchgit/nix-prefetch-git
diff options
context:
space:
mode:
authorTom McLaughlin <tom@codedown.io>2020-11-23 11:08:07 -0700
committerTom McLaughlin <tom@codedown.io>2021-02-13 22:12:08 -0800
commit6779902b32a208f39ab5d073714a12a7ac72bcf1 (patch)
tree32d9cc89a3a5793c8ccd6309b6d933f2b27c24ac /pkgs/build-support/fetchgit/nix-prefetch-git
parent4c9e23d6ad66de77dbc4ca80d3cbca7fdb3b06fb (diff)
fetchgit: support passing tree hashes as "rev"
Diffstat (limited to 'pkgs/build-support/fetchgit/nix-prefetch-git')
-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 3cb115c5e6e6..fc633506fbe7 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.