Skip to content

libfetchers/git: add support for '.' in gitmodules#13757

Merged
roberth merged 1 commit intoNixOS:masterfrom
fzakaria:issue-13215
Aug 18, 2025
Merged

libfetchers/git: add support for '.' in gitmodules#13757
roberth merged 1 commit intoNixOS:masterfrom
fzakaria:issue-13215

Conversation

@fzakaria
Copy link
Contributor

@fzakaria fzakaria commented Aug 15, 2025

Motivation

Please see #13215

Basically, .gitmodules file may have . as the branch listed for a submodule.
The git-documentation claims this is a "special" branch that represents it should be identical to the parent repository. [ref]

Validation

broken

[----------] 1 test from GitTest
[ RUN      ] GitTest.submodule_period_support
unknown file: Failure
C++ exception with description "error:
       … while fetching the input 'git+file:///tmp/nix-120109-2774730724/repo?ref=main&submodules=1'

       error: invalid Git branch/tag name '.'" thrown in the test body.

[  FAILED  ] GitTest.submodule_period_support (20 ms)
[----------] 1 test from GitTest (20 ms total)

fixed

meson test -C build nix-fetchers-tests
ninja: Entering directory `/home/fmzakari/code/github.com/NixOS/nix/build'
[2/2] Linking target src/libfetchers-tests/nix-fetchers-tests
1/1 libfetchers-tests / nix-fetchers-tests        OK              0.08s

Alternatively, I made a demo repo with this feature.

> cat /tmp/test/.gitmodules
[submodule "nix-auto-follow"]
	path = nix-auto-follow
  url = https://github.com/fzakaria/nix-auto-follow.git
  branch = .

> _NIX_FORCE_HTTP=1 ./build/src/nix/nix eval --impure --expr 'builtins.fetchGit { url="file:///tmp/test"; submodules=true; }'
{ lastModified = 1755229090; lastModifiedDate = "20250815033810"; narHash = "sha256-yNOsLiJAtS/atdWMto3usCEBmerWonCVoe557zQRvt4="; outPath = "/nix/store/3mcd25dyi8nfz84zxlz8v3bg0ch9crbz-source"; rev = "9e37ffc3ab465887b20be4ac42224e483706cefc"; revCount = 1; shortRev = "9e37ffc"; submodules = true; }

fixes #13215


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@fzakaria fzakaria requested a review from edolstra as a code owner August 15, 2025 05:21
@github-actions github-actions bot added the fetching Networking with the outside (non-Nix) world, input locking label Aug 15, 2025
@fzakaria

This comment was marked as resolved.

// TODO: can this be an in-memory store somehow?
Path storeTmpDir = createTempDir();
auto storeTmpDirAutoDelete = AutoDelete(storeTmpDir, true);
ref<Store> store = openStore(storeTmpDir);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think @Ericson2314 had a old PR to make dummy:// use more in-memory stuff. Would that be useful here? That never got merged.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one #10915

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed on matrix.
I will like to pick it up; seems worthwhile -- I might also make it a separate store.

Either way I think it doesn't block this PR.

@fzakaria fzakaria changed the title Support for '.' as branch in gitmodules file libfetchers/git: add support for '.' in gitsubmodules Aug 15, 2025
@fzakaria fzakaria changed the title libfetchers/git: add support for '.' in gitsubmodules libfetchers/git: add support for '.' in gitmodules Aug 15, 2025
@fzakaria fzakaria requested a review from xokdvium August 17, 2025 20:33
Period '.' is a special branch name in the gitsubmodule file which
represents the branch of the parent repository [1].

We add support for this by registering the ref of the InputAccessor to
be that of the parent input if '.' is encountered.

Fixes NixOS#13215

[1]: man gitmodules
@roberth roberth merged commit aa0dc0d into NixOS:master Aug 18, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fetching Networking with the outside (non-Nix) world, input locking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bultins.fetchGit with submodules failes to clone branch .

3 participants