# Keep .git folder in when fetching a git repo

**URL:** https://discourse.nixos.org/t/keep-git-folder-in-when-fetching-a-git-repo/8590
**Category:** Help
**Created:** [August 15, 2020, 8:13pm UTC](https://discourse.nixos.org/t/keep-git-folder-in-when-fetching-a-git-repo/8590 "2020-08-15T20:13:51Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![tobiasBora](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/t/9de0a6/32.png) [@tobiasBora](https://discourse.nixos.org/u/tobiasBora)
#### Post date: [August 15, 2020, 8:13pm UTC](https://discourse.nixos.org/t/keep-git-folder-in-when-fetching-a-git-repo/8590/1 "2020-08-15T20:13:51Z")

</div>

Hello,

I’m packaging [Audiveris](https://github.com/Audiveris/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!

---

<div class="post-metadata">

### Author: ![Thra11](https://discourse.nixos.org/user_avatar/discourse.nixos.org/thra11/32/2384_2.png) [@Thra11](https://discourse.nixos.org/u/Thra11)
#### Post date: [August 15, 2020, 10:44pm UTC](https://discourse.nixos.org/t/keep-git-folder-in-when-fetching-a-git-repo/8590/2 "2020-08-15T22:44:41Z")

</div>

> [@tobiasBora](#):
>
> However, `fetchFromGitHub` does not keep the .git repository,

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`.

---

<div class="post-metadata">

### Author: ![jonringer](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jonringer/32/1348_2.png) [@jonringer](https://discourse.nixos.org/u/jonringer)
#### Post date: [August 16, 2020, 5:53am UTC](https://discourse.nixos.org/t/keep-git-folder-in-when-fetching-a-git-repo/8590/3 "2020-08-16T05:53:50Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Infinisil](https://discourse.nixos.org/user_avatar/discourse.nixos.org/infinisil/32/26523_2.png) [@Infinisil](https://discourse.nixos.org/u/Infinisil)
#### Post date: [August 16, 2020, 9:50pm UTC](https://discourse.nixos.org/t/keep-git-folder-in-when-fetching-a-git-repo/8590/4 "2020-08-16T21:50:43Z")

</div>

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

---

<div class="post-metadata">

### Author: ![jonringer](https://discourse.nixos.org/user_avatar/discourse.nixos.org/jonringer/32/1348_2.png) [@jonringer](https://discourse.nixos.org/u/jonringer)
#### Post date: [August 16, 2020, 11:07pm UTC](https://discourse.nixos.org/t/keep-git-folder-in-when-fetching-a-git-repo/8590/5 "2020-08-16T23:07:29Z")

</div>

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

---

<div class="post-metadata">

### Author: ![hmenke](https://discourse.nixos.org/user_avatar/discourse.nixos.org/hmenke/32/2369_2.png) [@hmenke](https://discourse.nixos.org/u/hmenke)
#### Post date: [August 17, 2020, 3:55am UTC](https://discourse.nixos.org/t/keep-git-folder-in-when-fetching-a-git-repo/8590/6 "2020-08-17T03:55:25Z")

</div>

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](https://sourceforge.net/p/gnuplot/gnuplot-main/ci/ef315e6f148bb3144726246cbf396aad53e3a000/) to make the build independent of Git.

See also this GitHub issue:

> <https://github.com/NixOS/nixpkgs/issues/8567>
>
> The hash of the \`cargo\` git repository returned by \`fetchgit\` has changed twice …already, even though the git revision didn't change (see de322b48b7006cf72d6adc37a833f2e045950536 and now #8566).
> 
> See also: #4752 and #4767
> 
> cc @bjornfor and @madjar (due to #4767).

---

<div class="post-metadata">

### Author: ![Thra11](https://discourse.nixos.org/user_avatar/discourse.nixos.org/thra11/32/2384_2.png) [@Thra11](https://discourse.nixos.org/u/Thra11)
#### Post date: [August 17, 2020, 9:57am UTC](https://discourse.nixos.org/t/keep-git-folder-in-when-fetching-a-git-repo/8590/7 "2020-08-17T09:57:19Z")

</div>

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](https://github.com/wch/r-source/wiki#adding-svn-information) 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.

---

<div class="post-metadata">

### Author: ![tobiasBora](https://discourse.nixos.org/letter_avatar_proxy/v4/letter/t/9de0a6/32.png) [@tobiasBora](https://discourse.nixos.org/u/tobiasBora)
#### Post date: [August 17, 2020, 10:55am UTC](https://discourse.nixos.org/t/keep-git-folder-in-when-fetching-a-git-repo/8590/8 "2020-08-17T10:55:11Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![samuela](https://discourse.nixos.org/user_avatar/discourse.nixos.org/samuela/32/2486_2.png) [@samuela](https://discourse.nixos.org/u/samuela)
#### Post date: [October 10, 2021, 6:36pm UTC](https://discourse.nixos.org/t/keep-git-folder-in-when-fetching-a-git-repo/8590/9 "2021-10-10T18:36:23Z")

</div>

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](https://github.com/NixOS/nixpkgs/blob/b52f9841b2aa70e2407bf44a960dae991a766c41/pkgs/development/python-modules/GitPython/default.nix#L38-L39)
