config_file: implement "gitdir/i" conditional Next to the "gitdir" conditional for including other configuration files, there's also a "gitdir/i" conditional. In contrast to the former one, path matching with "gitdir/i" is done case-insensitively. This commit implements the case-insensitive condition.
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
diff --git a/src/config_file.c b/src/config_file.c
index ba520fc..ffcdca7 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -1612,11 +1612,12 @@ static int parse_include(struct reader *reader,
return result;
}
-static int conditional_match_gitdir(
+static int do_match_gitdir(
int *matches,
const git_repository *repo,
const char *cfg_file,
- const char *value)
+ const char *value,
+ bool case_insensitive)
{
git_buf path = GIT_BUF_INIT;
int error, fnmatch_flags;
@@ -1640,9 +1641,10 @@ static int conditional_match_gitdir(
git_buf_puts(&path, "**");
fnmatch_flags = FNM_PATHNAME|FNM_LEADING_DIR;
+ if (case_insensitive)
+ fnmatch_flags |= FNM_IGNORECASE;
if ((error = p_fnmatch(path.ptr, git_repository_path(repo), fnmatch_flags)) < 0)
-
goto out;
*matches = (error == 0);
@@ -1652,11 +1654,30 @@ out:
return error;
}
+static int conditional_match_gitdir(
+ int *matches,
+ const git_repository *repo,
+ const char *cfg_file,
+ const char *value)
+{
+ return do_match_gitdir(matches, repo, cfg_file, value, false);
+}
+
+static int conditional_match_gitdir_i(
+ int *matches,
+ const git_repository *repo,
+ const char *cfg_file,
+ const char *value)
+{
+ return do_match_gitdir(matches, repo, cfg_file, value, true);
+}
+
static const struct {
const char *prefix;
int (*matches)(int *matches, const git_repository *repo, const char *cfg, const char *value);
} conditions[] = {
- { "gitdir:", conditional_match_gitdir }
+ { "gitdir:", conditional_match_gitdir },
+ { "gitdir/i:", conditional_match_gitdir_i }
};
static int parse_conditional_include(struct reader *reader,
diff --git a/tests/config/conditionals.c b/tests/config/conditionals.c
index 323bbae..83dd45c 100644
--- a/tests/config/conditionals.c
+++ b/tests/config/conditionals.c
@@ -76,6 +76,19 @@ void test_config_conditionals__gitdir(void)
git_buf_free(&path);
}
+void test_config_conditionals__gitdir_i(void)
+{
+ git_buf path = GIT_BUF_INIT;
+
+ git_buf_joinpath(&path, clar_sandbox_path(), "empty_standard_repo");
+ assert_condition_includes("gitdir/i", path.ptr, true);
+
+ git_buf_joinpath(&path, clar_sandbox_path(), "EMPTY_STANDARD_REPO");
+ assert_condition_includes("gitdir/i", path.ptr, true);
+
+ git_buf_free(&path);
+}
+
void test_config_conditionals__invalid_conditional_fails(void)
{
assert_condition_includes("foobar", ".git", false);