Keep .git folder in when fetching a git repo

Hello,

I’m packaging Audiveris, and during the build, there is a gradle task :git_build that tries to run a git command to get the current hash (I guess in order to provide information about the version used).

However, fetchFromGitHub does not keep the .git repository, so the git command fails. For now, I clone the repository locally, and include it with src = ./audiveris;, but it’s not suitable for production.

One solution would be to patch the gradle tasks to hard-code the output of git, but I don’t really like this idea, first because I don’t know anything about gradle, but also because I think nobody wants to maintain such patch.

What is the proper way to handle that issue?

Thanks!

1 Like

Strictly speaking, fetchFromGitHub doesn’t fetch the .git directory in the first place, it just downloads tarballs. You can probably use fetchgit instead of fetchFromGitHub, and set leaveDotGit = true.

2 Likes

also realize that leaving the .git will decrease reproducibility, and you may have issues with sha mismatches

pkgs.fetchgit with leaveDotGit is still pretty pure (not sure about deepClone though)

I thought the way in which git objects are packaged are not considered stable.

I have had nothing but headaches with leaveDotGit = true. Every once in a while I would get a random hash mismatch, which eventually got so annoying that I submitted a patch to the upstream repo to make the build independent of Git.

See also this GitHub issue:

I considered suggesting patching/substituting the source to remove the git revision check (and possibly just replace it with the rev). I do think that might still be the best solution.

Build scripts trying to introspect the version control are a pain. I can sort of see what people are trying to achieve when they add them, e.g. make it easy to trace an unknown binary back to the commit which it was built from, but they mostly just cause problems. See here for a fun example of a git mirror to some svn sources, which then has to provide a selection of workarounds to trick the build script into thinking it’s still an svn repo.

Thanks a lot everybody. So I understand that this is unpure, and I read that it could be possible to provide to the builder a “fake” git, where the outcome is hardcoded/cached in the file. I’m thinking that it may be the simpler/more general solution, is there any advances on an “official” solution to that solution? If not, what is the recommended method to create this fake git at build time?

It turns out that there’s a similar issue running the test suite for GitPython: https://github.com/NixOS/nixpkgs/blob/b52f9841b2aa70e2407bf44a960dae991a766c41/pkgs/development/python-modules/GitPython/default.nix#L38-L39