mirror of
https://git.proxmox.com/git/libgit2
synced 2025-08-02 20:52:13 +00:00
Fix crash with adding internal ignores
Depending on what you had done before adding new items to the internal ignores list, it was possible for the cache of ignore data to be uninitialized.
This commit is contained in:
parent
2eb4edf5f2
commit
1168410426
20
src/ignore.c
20
src/ignore.c
@ -205,6 +205,16 @@ cleanup:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int get_internal_ignores(git_attr_file **ign, git_repository *repo)
|
||||
{
|
||||
int error;
|
||||
|
||||
if (!(error = git_attr_cache__init(repo)))
|
||||
error = git_attr_cache__internal_file(repo, GIT_IGNORE_INTERNAL, ign);
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
int git_ignore_add_rule(
|
||||
git_repository *repo,
|
||||
const char *rules)
|
||||
@ -212,10 +222,7 @@ int git_ignore_add_rule(
|
||||
int error;
|
||||
git_attr_file *ign_internal;
|
||||
|
||||
error = git_attr_cache__internal_file(
|
||||
repo, GIT_IGNORE_INTERNAL, &ign_internal);
|
||||
|
||||
if (!error && ign_internal != NULL)
|
||||
if (!(error = get_internal_ignores(&ign_internal, repo)))
|
||||
error = parse_ignore_file(repo, rules, ign_internal);
|
||||
|
||||
return error;
|
||||
@ -227,10 +234,7 @@ int git_ignore_clear_internal_rules(
|
||||
int error;
|
||||
git_attr_file *ign_internal;
|
||||
|
||||
error = git_attr_cache__internal_file(
|
||||
repo, GIT_IGNORE_INTERNAL, &ign_internal);
|
||||
|
||||
if (!error && ign_internal != NULL)
|
||||
if (!(error = get_internal_ignores(&ign_internal, repo)))
|
||||
git_attr_file__clear_rules(ign_internal);
|
||||
|
||||
return error;
|
||||
|
@ -199,3 +199,18 @@ void test_status_ignore__adding_internal_ignores(void)
|
||||
cl_git_pass(git_status_should_ignore(&ignored, g_repo, "two.bar"));
|
||||
cl_assert(ignored);
|
||||
}
|
||||
|
||||
void test_status_ignore__add_internal_as_first_thing(void)
|
||||
{
|
||||
int ignored;
|
||||
const char *add_me = "\n#################\n## Eclipse\n#################\n\n*.pydevproject\n.project\n.metadata\nbin/\ntmp/\n*.tmp\n\n";
|
||||
|
||||
g_repo = cl_git_sandbox_init("empty_standard_repo");
|
||||
|
||||
cl_git_pass(git_ignore_add_rule(g_repo, add_me));
|
||||
|
||||
cl_git_pass(git_status_should_ignore(&ignored, g_repo, "one.tmp"));
|
||||
cl_assert(ignored);
|
||||
cl_git_pass(git_status_should_ignore(&ignored, g_repo, "two.bar"));
|
||||
cl_assert(!ignored);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user