Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 727ae38

Browse files
committed
Make config reading continue after hitting a missing include file.
For example, if you have [include] path = foo and foo didn't exist, git_config_open_ondisk() would just give up on the rest of the file. Now it ignores the unresolved include without error and continues reading the rest of the file.
1 parent 264d74f commit 727ae38

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/config_file.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,7 @@ static int config_parse(git_strmap *values, diskfile_backend *cfg_file, struct r
12691269
if ((result = git_path_dirname_r(&path, reader->file_path)) < 0)
12701270
break;
12711271

1272-
/* We need to know out index in the array, as the next config_parse call may realloc */
1272+
/* We need to know our index in the array, as the next config_parse call may realloc */
12731273
index = git_array_size(cfg_file->readers) - 1;
12741274
dir = git_buf_detach(&path);
12751275
result = included_path(&path, dir, var->entry->value);
@@ -1280,12 +1280,11 @@ static int config_parse(git_strmap *values, diskfile_backend *cfg_file, struct r
12801280

12811281
r->file_path = git_buf_detach(&path);
12821282
git_buf_init(&r->buffer, 0);
1283-
if ((result = git_futils_readbuffer_updated(&r->buffer, r->file_path, &r->file_mtime,
1284-
&r->file_size, NULL)) < 0)
1285-
break;
1286-
1287-
result = config_parse(values, cfg_file, r, level, depth+1);
1288-
r = git_array_get(cfg_file->readers, index);
1283+
if (git_futils_readbuffer_updated(&r->buffer, r->file_path, &r->file_mtime,
1284+
&r->file_size, NULL) == 0) {
1285+
result = config_parse(values, cfg_file, r, level, depth+1);
1286+
r = git_array_get(cfg_file->readers, index);
1287+
}
12891288
git_buf_free(&r->buffer);
12901289

12911290
if (result < 0)

tests/config/include.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,18 @@ void test_config_include__depth(void)
8686
unlink("a");
8787
unlink("b");
8888
}
89+
90+
void test_config_include__missing(void)
91+
{
92+
git_config *cfg;
93+
const char *str;
94+
95+
cl_git_mkfile("included", "[include]\npath = nonexistentfile\n[foo]\nbar = baz");
96+
97+
cl_git_pass(git_config_open_ondisk(&cfg, "included"));
98+
cl_git_pass(git_config_get_string(&str, cfg, "foo.bar"));
99+
cl_assert_equal_s(str, "baz");
100+
101+
git_config_free(cfg);
102+
unlink("included");
103+
}

0 commit comments

Comments
 (0)