Skip to content

Commit 2d646e3

Browse files
committed
Merge branch 'jk/ls-files-recurse-submodules-fix'
"ls-files --recurse-submodules" did not quite work well in a project with nested submodules. * jk/ls-files-recurse-submodules-fix: ls-files: fix path used when recursing into submodules ls-files: fix recurse-submodules with nested submodules
2 parents f9096db + 2cfe66a commit 2d646e3

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

builtin/ls-files.c

Lines changed: 8 additions & 1 deletion
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;
@@ -202,6 +203,10 @@ static void show_gitlink(const struct cache_entry *ce)
202203
{
203204
struct child_process cp = CHILD_PROCESS_INIT;
204205
int status;
206+
char *dir;
207+
208+
prepare_submodule_repo_env(&cp.env_array);
209+
argv_array_push(&cp.env_array, GIT_DIR_ENVIRONMENT);
205210

206211
if (prefix_len)
207212
argv_array_pushf(&cp.env_array, "%s=%s",
@@ -217,8 +222,10 @@ static void show_gitlink(const struct cache_entry *ce)
217222
argv_array_pushv(&cp.args, submodule_options.argv);
218223

219224
cp.git_cmd = 1;
220-
cp.dir = ce->name;
225+
dir = mkpathdup("%s/%s", get_git_work_tree(), ce->name);
226+
cp.dir = dir;
221227
status = run_command(&cp);
228+
free(dir);
222229
if (status)
223230
exit(status);
224231
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,22 @@ 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
'
8384

85+
test_expect_success 'ls-files works with GIT_DIR' '
86+
cat >expect <<-\EOF &&
87+
.gitmodules
88+
c
89+
subsub/d
90+
EOF
91+
92+
git --git-dir=submodule/.git ls-files --recurse-submodules >actual &&
93+
test_cmp expect actual
94+
'
95+
8496
test_expect_success '--recurse-submodules and pathspecs setup' '
8597
echo e >submodule/subsub/e.txt &&
8698
git -C submodule/subsub add e.txt &&

0 commit comments

Comments
 (0)