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

fetchGit fails when trying to fetch from a repository that doesn't have master #1923

Closed
knedlsepp opened this issue Feb 28, 2018 · 10 comments
Closed

Comments

@knedlsepp
Copy link
Member

When trying to fetch a git revision of a repository that doesn't have a master branch, I get the following error

fatal: Couldn't find remote ref master

Example:

cat << EOF | nix repl
builtins.fetchGit {
  url = https://github.com/conradsnicta/armadillo-code;
  rev = "8696c7ef3a7e66e92558b438182b7ee5878f028f";
}
EOF

This can be resolved by additionally specifying the branch which includes the commit as ref:

cat << EOF | nix repl
builtins.fetchGit {
  url = https://github.com/conradsnicta/armadillo-code;
  ref = "unstable";
  rev = "8696c7ef3a7e66e92558b438182b7ee5878f028f";
}
EOF

While the issue itself is solvable via specifying the ref, this behavior is however rather surprising.

@knedlsepp knedlsepp changed the title fetchGit fails when trying to fetch a revision that is not in master fetchGit fails when trying to fetch from a repository that doesn't have master Feb 28, 2018
@dtzWill
Copy link
Member

dtzWill commented Feb 28, 2018

I suspect this means that fetchgit on a url with a default branch other than master won't work. IIRC the code sets ref to master if not otherwise set.

Perhaps this should be "HEAD" instead? (untested)

@dtzWill
Copy link
Member

dtzWill commented Feb 28, 2018

Yes, problem happens with bare URL too, as in builtins.fetchGit https://github.com/conradsnicta/armadillo-code.

HEAD seems reasonable and seems to work.

This would change the behavior but AFAICT it's not documented to prefer "master" so hopefully that's not a problem.

Change is trivial if it's what we want: dtzWill@51efd3b

@knedlsepp
Copy link
Member Author

Thanks for the quick diagnosis. I guess there is a strong argument for HEAD.

@eqyiel
Copy link

eqyiel commented Apr 19, 2018

I've been seeing an issue that may be related, fetchGit doesn't appear to work for revisions that aren't in master.

For example, this is the output when trying to fetch a revision from a different branch:

❯ nix-build --expr 'with import <nixpkgs> {}; callPackage ./default.nix {}' --no-out-link
fatal: not a tree object
error: program 'git' failed with exit code 128
(use '--show-trace' to show detailed location information)

@eqyiel
Copy link

eqyiel commented Apr 19, 2018

Can be reproduced like this using some old unmerged nixpkgs branch: https://github.com/NixOS/nixpkgs/tree/gnu-kfreebsd

❯ nix repl
Welcome to Nix version 2.1pre6149_b37f5ae3. Type :? for help.

nix-repl> builtins.fetchGit { url = "https://github.com/NixOS/nixpkgs.git"; rev = "3dc6915610c1267331a95a3b533f3a0f2e69b81d"; }
fetching Git repository 'https://github.com/NixOS/nixpkgs.git'warning: no common commits
fatal: not a tree object
error: program 'git' failed with exit code 128

nix-repl> builtins.fetchGit { url = "https://github.com/NixOS/nixpkgs.git"; rev = "3dc6915610c1267331a95a3b533f3a0f2e69b81d"; ref = "gnu-kfreebsd"; }
tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors
error: interrupted by the user

nix-repl>

@manveru
Copy link
Contributor

manveru commented May 14, 2018

I've got the same issue with not a tree object. For some reason doing the same fetchGit from nix repl instead of nix build fetches the correct revision.

@eqyiel
Copy link

eqyiel commented Jun 24, 2018

@shlevy could this be re-opened?

@copumpkin copumpkin reopened this Jun 26, 2018
@graham-at-target
Copy link
Contributor

fetching Git repository 'https://github.com/NixOS/nixpkgs.git'
{ outPath = "/nix/store/kq2lk2v3alv4yhb0y8ayblp50qxbhpbq-source"; rev = "3dc6915610c1267331a95a3b533f3a0f2e69b81d"; revCount = 9035; shortRev = "3dc6915"; }```

Works for me, so I think this can be closed.

@fogti
Copy link
Contributor

fogti commented Dec 24, 2021

I think I also ran into this (see also: https://cl.tvl.fyi/c/depot/+/4552/1):

[zseri@orca:~/devel/depot]$ nix-build --no-out-link --attr "tools.depot-scanner" "$DEPOT_ROOT" --show-trace
fatal: couldn't find remote ref refs/heads/master
error: program 'git' failed with exit code 128

       … while fetching the input 'git+https://github.com/google/go-genproto?rev=83cc0476cb11ea0da33dacd4c6354ab192de6fe6'

in
nix-env (Nix) 2.6.0pre20211223_af553b2

@EzekielEnns
Copy link

I know this is closed, but for anyone else who lost their sanity trying to fix:

$  nix-shell default.nix
error: executing 'git': No such file or directory
error: program 'git' failed with exit code 1

check if your nix shell or local machine has git installed
a simple nix-shell default.nix -p git should do the trick,
but what I did was just jumped into another shell with git in it:

$  nix-shell -p git
$  nix-shell default.nix

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

9 participants