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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
diff --git a/src/path.c b/src/path.c
index e135e3b..7aa7b53 100644
--- a/src/path.c
+++ b/src/path.c
@@ -1840,3 +1840,16 @@ int git_path_normalize_slashes(git_buf *out, const char *path)
return 0;
}
+
+static int verify_dotgit_generic(const char *name, const char *dotgit_name, const char *shortname_pfix)
+{
+ if (!verify_dotgit_ntfs_generic(name, dotgit_name, shortname_pfix))
+ return false;
+
+ return verify_dotgit_hfs_generic(name, strlen(name), dotgit_name, strlen(dotgit_name));
+}
+
+int git_path_is_dotgit_modules(const char *name)
+{
+ return !verify_dotgit_generic(name, "gitmodules", "gi7eba");
+}
diff --git a/tests/path/dotgit.c b/tests/path/dotgit.c
new file mode 100644
index 0000000..41174b1
--- /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);
+ }
+
+}