Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

builtins.fetchGit fails on (clean) shallow clones #2988

Closed
Kha opened this issue Jul 12, 2019 · 1 comment
Closed

builtins.fetchGit fails on (clean) shallow clones #2988

Kha opened this issue Jul 12, 2019 · 1 comment
Assignees

Comments

@Kha
Copy link
Contributor

Kha commented Jul 12, 2019

I'm trying to use fetchGit as a saner replacement for .gitignore/whitelist sources as detailed in #2944:

  src = if builtins.pathExists ./.git then builtins.fetchGit { url = ./.; } else ./.;

Unfortunately, this fails on Travis because Travis (sensibly) does a shallow clone by default. It seems this breaks fetchGit iff the working tree is clean:

$ git clone https://github.com/parttimenerd/temci.git --depth 1
[...]
$ cd temci
$ nix-build
warning: reject refs/heads/HEAD because shallow roots are not allowed to be updated
error: Could not read 9208ca8e91d8e707baeb3ce99750be94ea5d676d
fatal: Failed to traverse parents of commit 201ae68c5595d111d0605c13471a5c2de33bb3ec
error: program 'git' failed with exit code 128
(use '--show-trace' to show detailed location information)
# make it dirty
$ echo >> default.nix
$ nix-build
these derivations will be built:
[...]

My current workaround is to do something like nix-build --arg src ./. on Travis, but it would be great if I didn't need that.

@FRidh
Copy link
Member

FRidh commented Jul 13, 2019

It can't do shallow fetches yet, so I suppose it would also fail to check out an already shallow repo
#1837

@edolstra edolstra self-assigned this Mar 16, 2020
edolstra added a commit that referenced this issue Mar 16, 2020
Also, don't return a revCount anymore for shallow or dirty Git trees,
since it's incorrect.

Closes #2988.
edolstra added a commit that referenced this issue Mar 17, 2020
If you do a fetchTree on a Git repository, whether the result contains
a revCount attribute should not depend on whether that repository
happens to be a shallow clone or not. That would complicate caching a
lot and would be semantically messy. So applying fetchTree/fetchGit to
a shallow repository is now an error unless you pass the attribute
'shallow = true'. If 'shallow = true', we don't return revCount, even
if the repository is not actually shallow.

Note that Nix itself is not doing shallow clones at the moment. But it
could do so as an optimisation if the user specifies 'shallow = true'.

Issue #2988.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants