diff options
| author | Carlos Martín Nieto <carlosmn@github.com> | 2018-05-16 15:42:08 +0200 |
|---|---|---|
| committer | Carlos Martín Nieto <carlosmn@github.com> | 2018-05-18 14:49:08 +0200 |
| commit | 9de97ae75d6a27d4eca5c8de90c3577fae726325 (patch) | |
| tree | 5af4dbb34b6a4e8feaf56a11189ce22748e996dd /tests/path | |
| parent | 22973e099e85211470b6bc26c55d7cf9f7934079 (diff) | |
| download | libgit2-9de97ae75d6a27d4eca5c8de90c3577fae726325.tar.gz | |
path: add a function to detect an .gitmodules file
Given a path component it knows what to pass to the filesystem-specific
functions so we're protected even from trees which try to use the 8.3 naming
rules to get around us matching on the filename exactly.
The logic and test strings come from the equivalent git change.
Diffstat (limited to 'tests/path')
| -rw-r--r-- | tests/path/dotgit.c | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/tests/path/dotgit.c b/tests/path/dotgit.c new file mode 100644 index 000000000..41174b133 --- /dev/null +++ b/tests/path/dotgit.c @@ -0,0 +1,110 @@ +#include "clar_libgit2.h" +#include "path.h" + +#include "git2/sys/path.h" + +static char *gitmodules_altnames[] = { + ".gitmodules", + + ".git\u200cmodules", + + ".Gitmodules", + ".gitmoduleS", + + ".gitmodules ", + ".gitmodules.", + ".gitmodules ", + ".gitmodules. ", + ".gitmodules .", + ".gitmodules..", + ".gitmodules ", + ".gitmodules. ", + ".gitmodules . ", + ".gitmodules .", + + ".Gitmodules ", + ".Gitmodules.", + ".Gitmodules ", + ".Gitmodules. ", + ".Gitmodules .", + ".Gitmodules..", + ".Gitmodules ", + ".Gitmodules. ", + ".Gitmodules . ", + ".Gitmodules .", + + "GITMOD~1", + "gitmod~1", + "GITMOD~2", + "gitmod~3", + "GITMOD~4", + + "GITMOD~1 ", + "gitmod~2.", + "GITMOD~3 ", + "gitmod~4. ", + "GITMOD~1 .", + "gitmod~2 ", + "GITMOD~3. ", + "gitmod~4 . ", + + "GI7EBA~1", + "gi7eba~9", + + "GI7EB~10", + "GI7EB~11", + "GI7EB~99", + "GI7EB~10", + "GI7E~100", + "GI7E~101", + "GI7E~999", + "~1000000", + "~9999999", +}; + +static char *gitmodules_not_altnames[] = { + ".gitmodules x", + ".gitmodules .x", + + " .gitmodules", + + "..gitmodules", + + "gitmodules", + + ".gitmodule", + + ".gitmodules x ", + ".gitmodules .x", + + "GI7EBA~", + "GI7EBA~0", + "GI7EBA~~1", + "GI7EBA~X", + "Gx7EBA~1", + "GI7EBX~1", + + "GI7EB~1", + "GI7EB~01", + "GI7EB~1", +}; + +void test_path_dotgit__dotgit_modules(void) +{ + size_t i; + cl_assert_equal_i(1, git_path_is_dotgit_modules(".gitmodules")); + cl_assert_equal_i(1, git_path_is_dotgit_modules(".git\xe2\x80\x8cmodules")); + + for (i = 0; i < ARRAY_SIZE(gitmodules_altnames); i++) { + const char *name = gitmodules_altnames[i]; + if (!git_path_is_dotgit_modules(name)) + cl_fail(name); + } + + for (i = 0; i < ARRAY_SIZE(gitmodules_not_altnames); i++) { + const char *name = gitmodules_not_altnames[i]; + if (git_path_is_dotgit_modules(name)) + cl_fail(name); + } + +} |
