Merge pull request #10176 from Ericson2314/fetchgitLocal

Rewrite `fetchgitLocal`
This commit is contained in:
Eric Seidel 2015-10-07 18:37:35 -07:00
commit 9be18c4d07

View File

@ -1,23 +1,40 @@
{ runCommand, git, nix }: src: { runCommand, git, nix }: src:
let hash = import (runCommand "head-hash.nix" let
{ dummy = builtins.currentTime; srcStr = toString src;
preferLocalBuild = true; }
''
cd ${toString src}
(${git}/bin/git show && ${git}/bin/git diff) > $out
hash=$(${nix}/bin/nix-hash $out)
echo "\"$hash\"" > $out
''); in
runCommand "local-git-export" # Adds the current directory (respecting ignored files) to the git store, and returns the hash
{ dummy = hash; gitHashFile = runCommand "put-in-git" {
preferLocalBuild = true; } nativeBuildInputs = [ git ];
'' dummy = builtins.currentTime; # impure, do every time
cd ${toString src} preferLocalBuild = true;
mkdir -p "$out" } ''
for file in $(${git}/bin/git ls-files); do cd ${srcStr}
mkdir -p "$out/$(dirname $file)" ROOT=$(git rev-parse --show-toplevel) # path to repo
cp -d $file "$out/$file" || true # don't fail when trying to copy a directory
done cp $ROOT/.git/index $ROOT/.git/index-user # backup index
'' git reset # reset index
git add . # add current directory
# hash of current directory
# remove trailing newline
git rev-parse $(git write-tree) \
| tr -d '\n' > $out
mv $ROOT/.git/index-user $ROOT/.git/index # restore index
'';
gitHash = builtins.readFile gitHashFile; # cache against git hash
nixPath = runCommand "put-in-nix" {
nativeBuildInputs = [ git ];
preferLocalBuild = true;
} ''
mkdir $out
# dump tar of *current directory* at given revision
git -C ${srcStr} archive --format=tar ${gitHash} \
| tar xvf - -C $out
'';
in nixPath