From aa00a5a8c9ba7b74c2102b8dc7fc4c3ed58606d8 Mon Sep 17 00:00:00 2001 From: Alois Wohlschlager Date: Wed, 12 Jun 2024 19:42:38 +0200 Subject: [PATCH] libfetchers: represent unfetched submodules consistently Unfetched submodules are included as empty directories in archives, so they end up as such in the store when fetched in clean mode. Make sure the same happens in dirty mode too. Fortunately, they are already correctly represented in the ls-files output, so we just need to make sure to include the empty directory in our filter. Fixes: https://github.com/NixOS/nix/issues/6247 Change-Id: I60d06ff360cfa305d081b920838c893c06da801c --- src/libfetchers/git.cc | 2 +- tests/functional/fetchGitSubmodules.sh | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libfetchers/git.cc b/src/libfetchers/git.cc index 07cbc781c..2817fde23 100644 --- a/src/libfetchers/git.cc +++ b/src/libfetchers/git.cc @@ -232,7 +232,7 @@ std::pair fetchFromWorkdir(ref store, Input & input, co if (S_ISDIR(st.st_mode)) { auto prefix = file + "/"; auto i = files.lower_bound(prefix); - return i != files.end() && (*i).starts_with(prefix); + return (i != files.end() && (*i).starts_with(prefix)) || files.count(file); } return files.count(file); diff --git a/tests/functional/fetchGitSubmodules.sh b/tests/functional/fetchGitSubmodules.sh index df81232e5..3ff6697fd 100644 --- a/tests/functional/fetchGitSubmodules.sh +++ b/tests/functional/fetchGitSubmodules.sh @@ -40,6 +40,7 @@ initGitRepo $rootRepo git -C $rootRepo submodule init git -C $rootRepo submodule add $subRepo sub git -C $rootRepo add sub +r0=$(nix eval --impure --raw --expr "(builtins.fetchGit { url = file://$rootRepo; }).outPath") git -C $rootRepo commit -m "Add submodule" rev=$(git -C $rootRepo rev-parse HEAD) @@ -48,6 +49,7 @@ r1=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \ r2=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \"$rev\"; submodules = false; }).outPath") r3=$(nix eval --raw --expr "(builtins.fetchGit { url = file://$rootRepo; rev = \"$rev\"; submodules = true; }).outPath") +[[ $r0 == $r1 ]] # verify that unfetched submodules result in empty directories in dirty mode too [[ $r1 == $r2 ]] [[ $r2 != $r3 ]]