Skip to content

Commit 2b56bb7

Browse files
stefanbellergitster
authored andcommitted
submodule helper list: respect correct path prefix
This is a regression introduced by 74703a1 (submodule: rewrite `module_list` shell function in C, 2015-09-02). Add a test to ensure we list the right submodule when giving a specific pathspec. Reported-By: Caleb Jorden <[email protected]> Signed-off-by: Stefan Beller <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7548842 commit 2b56bb7

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

builtin/submodule--helper.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,12 @@ static int module_list_compute(int argc, const char **argv,
2222
struct module_list *list)
2323
{
2424
int i, result = 0;
25-
char *max_prefix, *ps_matched = NULL;
26-
int max_prefix_len;
25+
char *ps_matched = NULL;
2726
parse_pathspec(pathspec, 0,
2827
PATHSPEC_PREFER_FULL |
2928
PATHSPEC_STRIP_SUBMODULE_SLASH_CHEAP,
3029
prefix, argv);
3130

32-
/* Find common prefix for all pathspec's */
33-
max_prefix = common_prefix(pathspec);
34-
max_prefix_len = max_prefix ? strlen(max_prefix) : 0;
35-
3631
if (pathspec->nr)
3732
ps_matched = xcalloc(pathspec->nr, 1);
3833

@@ -44,7 +39,7 @@ static int module_list_compute(int argc, const char **argv,
4439

4540
if (!S_ISGITLINK(ce->ce_mode) ||
4641
!match_pathspec(pathspec, ce->name, ce_namelen(ce),
47-
max_prefix_len, ps_matched, 1))
42+
0, ps_matched, 1))
4843
continue;
4944

5045
ALLOC_GROW(list->entries, list->nr + 1, list->alloc);
@@ -57,7 +52,6 @@ static int module_list_compute(int argc, const char **argv,
5752
*/
5853
i++;
5954
}
60-
free(max_prefix);
6155

6256
if (ps_matched && report_path_error(ps_matched, pathspec, prefix))
6357
result = -1;

t/t7400-submodule-basic.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,5 +999,30 @@ test_expect_success 'submodule add clone shallow submodule' '
999999
)
10001000
'
10011001

1002+
test_expect_success 'submodule helper list is not confused by common prefixes' '
1003+
mkdir -p dir1/b &&
1004+
(
1005+
cd dir1/b &&
1006+
git init &&
1007+
echo hi >testfile2 &&
1008+
git add . &&
1009+
git commit -m "test1"
1010+
) &&
1011+
mkdir -p dir2/b &&
1012+
(
1013+
cd dir2/b &&
1014+
git init &&
1015+
echo hello >testfile1 &&
1016+
git add . &&
1017+
git commit -m "test2"
1018+
) &&
1019+
git submodule add /dir1/b dir1/b &&
1020+
git submodule add /dir2/b dir2/b &&
1021+
git commit -m "first submodule commit" &&
1022+
git submodule--helper list dir1/b |cut -c51- >actual &&
1023+
echo "dir1/b" >expect &&
1024+
test_cmp expect actual
1025+
'
1026+
10021027

10031028
test_done

0 commit comments

Comments
 (0)