mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-08 03:15:46 +00:00
Merge pull request #2679 from jfultz/missing-include
Make config reading continue after hitting a missing include file.
This commit is contained in:
commit
de0c4555da
@ -1269,7 +1269,7 @@ static int config_parse(git_strmap *values, diskfile_backend *cfg_file, struct r
|
|||||||
if ((result = git_path_dirname_r(&path, reader->file_path)) < 0)
|
if ((result = git_path_dirname_r(&path, reader->file_path)) < 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* We need to know out index in the array, as the next config_parse call may realloc */
|
/* We need to know our index in the array, as the next config_parse call may realloc */
|
||||||
index = git_array_size(cfg_file->readers) - 1;
|
index = git_array_size(cfg_file->readers) - 1;
|
||||||
dir = git_buf_detach(&path);
|
dir = git_buf_detach(&path);
|
||||||
result = included_path(&path, dir, var->entry->value);
|
result = included_path(&path, dir, var->entry->value);
|
||||||
@ -1280,12 +1280,18 @@ static int config_parse(git_strmap *values, diskfile_backend *cfg_file, struct r
|
|||||||
|
|
||||||
r->file_path = git_buf_detach(&path);
|
r->file_path = git_buf_detach(&path);
|
||||||
git_buf_init(&r->buffer, 0);
|
git_buf_init(&r->buffer, 0);
|
||||||
if ((result = git_futils_readbuffer_updated(&r->buffer, r->file_path, &r->file_mtime,
|
result = git_futils_readbuffer_updated(&r->buffer, r->file_path, &r->file_mtime,
|
||||||
&r->file_size, NULL)) < 0)
|
&r->file_size, NULL);
|
||||||
break;
|
|
||||||
|
if (result == 0) {
|
||||||
|
result = config_parse(values, cfg_file, r, level, depth+1);
|
||||||
|
r = git_array_get(cfg_file->readers, index);
|
||||||
|
}
|
||||||
|
else if (result == GIT_ENOTFOUND) {
|
||||||
|
giterr_clear();
|
||||||
|
result = 0;
|
||||||
|
}
|
||||||
|
|
||||||
result = config_parse(values, cfg_file, r, level, depth+1);
|
|
||||||
r = git_array_get(cfg_file->readers, index);
|
|
||||||
git_buf_free(&r->buffer);
|
git_buf_free(&r->buffer);
|
||||||
|
|
||||||
if (result < 0)
|
if (result < 0)
|
||||||
|
@ -86,3 +86,19 @@ void test_config_include__depth(void)
|
|||||||
unlink("a");
|
unlink("a");
|
||||||
unlink("b");
|
unlink("b");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_config_include__missing(void)
|
||||||
|
{
|
||||||
|
git_config *cfg;
|
||||||
|
const char *str;
|
||||||
|
|
||||||
|
cl_git_mkfile("including", "[include]\npath = nonexistentfile\n[foo]\nbar = baz");
|
||||||
|
|
||||||
|
giterr_clear();
|
||||||
|
cl_git_pass(git_config_open_ondisk(&cfg, "including"));
|
||||||
|
cl_assert(giterr_last() == NULL);
|
||||||
|
cl_git_pass(git_config_get_string(&str, cfg, "foo.bar"));
|
||||||
|
cl_assert_equal_s(str, "baz");
|
||||||
|
|
||||||
|
git_config_free(cfg);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user