Skip to content

fetchGit regression on empty repositories #10039

@infinisil

Description

@infinisil

Describe the bug

Empty repositories can't be fetched using fetchGit anymore:

error: bad optional access

Steps To Reproduce

❯ cd $(mktemp -d)
❯ git init
Initialized empty Git repository in /tmp/tmp.b1BBa2agoC/.git/
❯ nix eval --impure --expr 'builtins.fetchGit ./.'
error: bad optional access

Furthermore, once you add one commit:

❯ git commit --allow-empty --allow-empty-message --message ""
[main (root-commit) 9778840] 
❯ nix eval --impure --expr 'builtins.fetchGit ./.'
error (ignored): error: end of string reached
error:
       … while calling the 'fetchGit' builtin
         at «string»:1:1:
            1| builtins.fetchGit ./.
             | ^

       … while fetching the input 'git+file:///tmp/tmp.iFTTesKTpK?exportIgnore=1'

       error: access to path '/' is forbidden because it is not under Git control; maybe you should 'git add' it to the repository '/tmp/tmp.iFTTesKTpK'?

Expected behavior

The same as Nix 2.19:

❯ nix eval --impure --expr 'builtins.fetchGit ./.'
warning: Git tree '/tmp/tmp.b1BBa2agoC' is dirty
{ lastModified = 0; lastModifiedDate = "19700101000000"; narHash = "sha256-pQpattmS9VmO3ZIQUFn66az8GSmB4IvYhTTCFn6SUmo="; outPath = "/nix/store/0ccnxa25whszw7mgbgyzdm4nqc0zwnm8-source"; rev = "0000000000000000000000000000000000000000"; revCount = 0; shortRev = "0000000"; submodules = false; }

❯ git commit --allow-empty --allow-empty-message --message ""
[main (root-commit) 9778840] 
❯ result/bin/nix eval --impure --expr 'builtins.fetchGit ./.'
{ lastModified = 1708368780; lastModifiedDate = "20240219185300"; narHash = "sha256-pQpattmS9VmO3ZIQUFn66az8GSmB4IvYhTTCFn6SUmo="; outPath = "/nix/store/0ccnxa25whszw7mgbgyzdm4nqc0zwnm8-source"; rev = "9778840cfdd38c118297a3fbaad3e3cb9ea514fe"; revCount = 1; shortRev = "9778840"; submodules = false; }

nix-env --version output

nix-env (Nix) 2.21.0pre20240216_60936f2

Additional context

I already reported this issue 4 months ago in @edolstra's source tree abstraction PR!

This issue is sponsored by Antithesis

Priorities

Add 👍 to issues you find important.

Metadata

Metadata

Assignees

Labels

bugregressionSomething doesn't work anymore

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions