config: refresh included files We need to refresh the variables from the included files if they are changed, so loop over all included files and re-parse the files if any of them has changed.
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
diff --git a/src/config_file.c b/src/config_file.c
index 3732fd1..c835765 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -197,14 +197,25 @@ static int config_open(git_config_backend *cfg, git_config_level_t level)
static int config_refresh(git_config_backend *cfg)
{
- int res, updated = 0;
+ int res = 0, updated = 0, any_updated = 0;
diskfile_backend *b = (diskfile_backend *)cfg;
git_strmap *old_values;
- struct reader *reader = git_array_get(b->readers, 0);
+ struct reader *reader;
+ uint32_t i;
- res = git_futils_readbuffer_updated(
- &reader->buffer, b->file_path, &reader->file_mtime, &reader->file_size, &updated);
- if (res < 0 || !updated)
+ for (i = 0; i < git_array_size(b->readers); i++) {
+ reader = git_array_get(b->readers, i);
+ res = git_futils_readbuffer_updated(
+ &reader->buffer, reader->file_path, &reader->file_mtime, &reader->file_size, &updated);
+
+ if (res < 0)
+ return (res == GIT_ENOTFOUND) ? 0 : res;
+
+ if (updated)
+ any_updated = 1;
+ }
+
+ if (!any_updated)
return (res == GIT_ENOTFOUND) ? 0 : res;
/* need to reload - store old values and prep for reload */
diff --git a/tests-clar/config/include.c b/tests-clar/config/include.c
index b88a7b2..94669a5 100644
--- a/tests-clar/config/include.c
+++ b/tests-clar/config/include.c
@@ -48,3 +48,26 @@ void test_config_include__homedir(void)
git_config_free(cfg);
}
+
+void test_config_include__refresh(void)
+{
+ git_config *cfg;
+ const char *str;
+
+ cl_fixture_sandbox("config");
+
+ cl_git_pass(git_config_open_ondisk(&cfg, "config/config-include"));
+
+ cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.baz"));
+ cl_assert_equal_s(str, "huzzah");
+
+ /* Change the included file and see if we refresh */
+ cl_git_mkfile("config/config-included", "[foo \"bar\"]\nbaz = hurrah");
+ cl_git_pass(git_config_refresh(cfg));
+
+ cl_git_pass(git_config_get_string(&str, cfg, "foo.bar.baz"));
+ cl_assert_equal_s(str, "hurrah");
+
+ git_config_free(cfg);
+ cl_fixture_cleanup("config");
+}