Skip to content

Commit dc2d9ba

Browse files
dschopeff
authored andcommitted
is_{hfs,ntfs}_dotgitmodules: add tests
This tests primarily for NTFS issues, but also adds one example of an HFS+ issue. Thanks go to Congyi Wu for coming up with the list of examples where NTFS would possibly equate the filename with `.gitmodules`. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Jeff King <[email protected]>
1 parent e7cb0b4 commit dc2d9ba

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed

t/helper/test-path-utils.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "cache.h"
22
#include "string-list.h"
3+
#include "utf8.h"
34

45
/*
56
* A "string_list_each_func_t" function that normalizes an entry from
@@ -156,6 +157,11 @@ static struct test_data dirname_data[] = {
156157
{ NULL, NULL }
157158
};
158159

160+
static int is_dotgitmodules(const char *path)
161+
{
162+
return is_hfs_dotgitmodules(path) || is_ntfs_dotgitmodules(path);
163+
}
164+
159165
int cmd_main(int argc, const char **argv)
160166
{
161167
if (argc == 3 && !strcmp(argv[1], "normalize_path_copy")) {
@@ -256,6 +262,20 @@ int cmd_main(int argc, const char **argv)
256262
if (argc == 2 && !strcmp(argv[1], "dirname"))
257263
return test_function(dirname_data, dirname, argv[1]);
258264

265+
if (argc > 2 && !strcmp(argv[1], "is_dotgitmodules")) {
266+
int res = 0, expect = 1, i;
267+
for (i = 2; i < argc; i++)
268+
if (!strcmp("--not", argv[i]))
269+
expect = !expect;
270+
else if (expect != is_dotgitmodules(argv[i]))
271+
res = error("'%s' is %s.gitmodules", argv[i],
272+
expect ? "not " : "");
273+
else
274+
fprintf(stderr, "ok: '%s' is %s.gitmodules\n",
275+
argv[i], expect ? "" : "not ");
276+
return !!res;
277+
}
278+
259279
fprintf(stderr, "%s: unknown function name: %s\n", argv[0],
260280
argv[1] ? argv[1] : "(there was none)");
261281
return 1;

t/t0060-path-utils.sh

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,4 +349,90 @@ test_submodule_relative_url "(null)" "ssh://hostname:22/repo" "../subrepo" "ssh:
349349
test_submodule_relative_url "(null)" "user@host:path/to/repo" "../subrepo" "user@host:path/to/subrepo"
350350
test_submodule_relative_url "(null)" "user@host:repo" "../subrepo" "user@host:subrepo"
351351

352+
test_expect_success 'match .gitmodules' '
353+
test-path-utils is_dotgitmodules \
354+
.gitmodules \
355+
\
356+
.git${u200c}modules \
357+
\
358+
.Gitmodules \
359+
.gitmoduleS \
360+
\
361+
".gitmodules " \
362+
".gitmodules." \
363+
".gitmodules " \
364+
".gitmodules. " \
365+
".gitmodules ." \
366+
".gitmodules.." \
367+
".gitmodules " \
368+
".gitmodules. " \
369+
".gitmodules . " \
370+
".gitmodules ." \
371+
\
372+
".Gitmodules " \
373+
".Gitmodules." \
374+
".Gitmodules " \
375+
".Gitmodules. " \
376+
".Gitmodules ." \
377+
".Gitmodules.." \
378+
".Gitmodules " \
379+
".Gitmodules. " \
380+
".Gitmodules . " \
381+
".Gitmodules ." \
382+
\
383+
GITMOD~1 \
384+
gitmod~1 \
385+
GITMOD~2 \
386+
gitmod~3 \
387+
GITMOD~4 \
388+
\
389+
"GITMOD~1 " \
390+
"gitmod~2." \
391+
"GITMOD~3 " \
392+
"gitmod~4. " \
393+
"GITMOD~1 ." \
394+
"gitmod~2 " \
395+
"GITMOD~3. " \
396+
"gitmod~4 . " \
397+
\
398+
GI7EBA~1 \
399+
gi7eba~9 \
400+
\
401+
GI7EB~10 \
402+
GI7EB~11 \
403+
GI7EB~99 \
404+
GI7EB~10 \
405+
GI7E~100 \
406+
GI7E~101 \
407+
GI7E~999 \
408+
~1000000 \
409+
~9999999 \
410+
\
411+
--not \
412+
".gitmodules x" \
413+
".gitmodules .x" \
414+
\
415+
" .gitmodules" \
416+
\
417+
..gitmodules \
418+
\
419+
gitmodules \
420+
\
421+
.gitmodule \
422+
\
423+
".gitmodules x " \
424+
".gitmodules .x" \
425+
\
426+
GI7EBA~ \
427+
GI7EBA~0 \
428+
GI7EBA~~1 \
429+
GI7EBA~X \
430+
Gx7EBA~1 \
431+
GI7EBX~1 \
432+
\
433+
GI7EB~1 \
434+
GI7EB~01 \
435+
GI7EB~1X
436+
'
437+
352438
test_done

0 commit comments

Comments
 (0)