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
fetchGit: allow fetching revs which are not ancestors of HEAD without specifying a ref #3408
fetchGit: allow fetching revs which are not ancestors of HEAD without specifying a ref #3408
Conversation
This is to work around a bug in `builtins.fetchGit` where specifying a `rev` which is not an ancestor of HEAD results in a git error. When setting `ref` to `rev` we force Nix to fetch the `rev`. TODO: This hack can be removed once the following is merged and released: NixOS/nix#3408
In the past we've decided that |
Why does it require cloning an entire repository? Only fetching |
Also when both specifying a |
BTW the reason I need this is that in I currently work around this by setting
|
Git in general does not allow fetching an arbitrary revision from a remote for security reasons. (IIRC there is a server setting to disable this check.) You have to specify a ref that contains the revision. |
abb4ffe
to
9eb6dff
Compare
TIL that git servers indeed don't allow fetching revisions directly by default (GitHub however does). So if this is parameterizable on the server, what about making it parameterizable on the client as well? I forced-pushed a proposal for this where I introduce the This keeps the old semantics, although with the additional ancestor checks, but allows fetching revisions directly. @edolstra WDYT? |
5f26a2b
to
fa43782
Compare
… specifying a ref Note that `builtins.fetchGit` defaults `ref` to `HEAD` when not specified. This is problematic when fetching a `rev` which is not an ancestor of `HEAD` when no `ref` is available: ``` nix-instantiate -v --eval -E 'builtins.fetchGit { url = "https://github.com/.../..."; rev = "9ec3a6973f6a17dc4b2566520253fc6203f75ac6"; }' evaluating file '/nix/store/lrnvapsqmf0ja6zfyx4cpxr7ahdr7f9b-nix-2.3.3/share/nix/corepkgs/derivation.nix' fetching Git repository 'https://github.com/.../...'... using revision 9ec3a6973f6a17dc4b2566520253fc6203f75ac6 of repo 'https://github.com/.../...' fatal: not a tree object: 9ec3a6973f6a17dc4b2566520253fc6203f75ac6 error: program 'git' failed with exit code 128 ``` This error occurs because `rev` is never fetched since it's not an ancestor of the ref `HEAD` which is fetched. This commit introduces the `fetchRevInsteadOfRef` argument to `builtins.fetchGit` which when `true` fetches the `rev` directly instead of fetching `HEAD`. `fetchRevInsteadOfRef` defaults to `false` to keep backwards compatibility and since git servers by default [don't allow fetching revisions directly](https://www.git-scm.com/docs/git-config/2.25.1#Documentation/git-config.txt-uploadpackallowAnySHA1InWant) (Note that GitHub does allow this). This commit now also checks whether `rev` is an ancestor of `ref` when the latter is specified.
fa43782
to
2f849a4
Compare
@basvandijk GitHub does not allow fetching 'unadvertised refs' (one of the heads or tags, basically), which is the git default. We work around this by specifying |
@yorickvP what's the
|
It's a git thing, |
This is required so that fetching dependencies from a feature branch is possible. See also NixOS/nix#3408
This is required so that fetching dependencies from a feature branch is possible. See also NixOS/nix#3408
This is required so that fetching dependencies from a feature branch is possible. See also NixOS/nix#3408
I marked this as stale due to inactivity. → More info |
I closed this issue due to inactivity. → More info |
Note that
builtins.fetchGit
defaultsref
toHEAD
when not specified. This is problematic when fetching arev
which is not an ancestor ofHEAD
when noref
is available:This error occurs because
rev
is never fetched since it's not an ancestor of the refHEAD
which is fetched.This commit introduces the
fetchRevInsteadOfRef
argument tobuiltins.fetchGit
which whentrue
fetches therev
directly instead of fetchingHEAD
.fetchRevInsteadOfRef
defaults tofalse
to keep backwards compatibility and since git servers by default don't allow fetching revisions directly (Note that GitHub does allow this).This commit now also checks whether
rev
is an ancestor ofref
when the latter is specified.