Skip to content

Commit 2e5d650

Browse files
jacob-kellergitster
authored andcommitted
ls-files: fix recurse-submodules with nested submodules
Since commit e77aa33 ("ls-files: optionally recurse into submodules", 2016-10-07) ls-files has known how to recurse into submodules when displaying files. Unfortunately this fails for certain cases, including when nesting more than one submodule, called from within a submodule that itself has submodules, or when the GIT_DIR environemnt variable is set. Prior to commit b58a68c ("setup: allow for prefix to be passed to git commands", 2017-03-17) this resulted in an error indicating that --prefix and --super-prefix were incompatible. After this commit, instead, the process loops forever with a GIT_DIR set to the parent and continuously reads the parent submodule files and recursing forever. Fix this by preparing the environment properly for submodules when setting up the child process. This is similar to how other commands such as grep behave. This was not caught by the original tests because the scenario is avoided if the submodules are created separately and not stored as the standard method of putting the submodule git directory under .git/modules/<name>. We can update the test to show the failure by the addition of "git submodule absorbgitdirs" to the test case. However, note that this new test would run forever without the necessary fix in this patch. Signed-off-by: Jacob Keller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 584f897 commit 2e5d650

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

builtin/ls-files.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "string-list.h"
1616
#include "pathspec.h"
1717
#include "run-command.h"
18+
#include "submodule.h"
1819

1920
static int abbrev;
2021
static int show_deleted;
@@ -203,6 +204,9 @@ static void show_gitlink(const struct cache_entry *ce)
203204
struct child_process cp = CHILD_PROCESS_INIT;
204205
int status;
205206

207+
prepare_submodule_repo_env(&cp.env_array);
208+
argv_array_push(&cp.env_array, GIT_DIR_ENVIRONMENT);
209+
206210
if (prefix_len)
207211
argv_array_pushf(&cp.env_array, "%s=%s",
208212
GIT_TOPLEVEL_PREFIX_ENVIRONMENT,

t/t3007-ls-files-recurse-submodules.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ test_expect_success 'ls-files recurses more than 1 level' '
7777
git -C submodule/subsub commit -m "add d" &&
7878
git -C submodule submodule add ./subsub &&
7979
git -C submodule commit -m "added subsub" &&
80+
git submodule absorbgitdirs &&
8081
git ls-files --recurse-submodules >actual &&
8182
test_cmp expect actual
8283
'

0 commit comments

Comments
 (0)