Skip to content

Commit 8164b48

Browse files
authored
Merge pull request libgit2#6521 from libgit2/ethomson/weird_ignore
2 parents af12fc1 + 129cadf commit 8164b48

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

src/libgit2/index.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3509,7 +3509,8 @@ static int index_apply_to_wd_diff(git_index *index, int action, const git_strarr
35093509
GIT_DIFF_RECURSE_UNTRACKED_DIRS;
35103510

35113511
if (flags == GIT_INDEX_ADD_FORCE)
3512-
opts.flags |= GIT_DIFF_INCLUDE_IGNORED;
3512+
opts.flags |= GIT_DIFF_INCLUDE_IGNORED |
3513+
GIT_DIFF_RECURSE_IGNORED_DIRS;
35133514
}
35143515

35153516
if ((error = git_diff_index_to_workdir(&diff, repo, index, &opts)) < 0)

tests/libgit2/index/addall.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,52 @@ void test_index_addall__callback_filtering(void)
441441
git_index_free(index);
442442
}
443443

444+
void test_index_addall__handles_ignored_files_in_directory(void)
445+
{
446+
git_index *index;
447+
448+
g_repo = cl_git_sandbox_init_new(TEST_DIR);
449+
450+
cl_git_mkfile(TEST_DIR "/file.foo", "a file");
451+
cl_git_mkfile(TEST_DIR "/file.bar", "another file");
452+
cl_must_pass(p_mkdir(TEST_DIR "/folder", 0777));
453+
cl_git_mkfile(TEST_DIR "/folder/asdf", "yet another file");
454+
455+
cl_git_mkfile(TEST_DIR "/.gitignore", "folder/\n");
456+
457+
check_status(g_repo, 0, 0, 0, 3, 0, 0, 1, 0);
458+
459+
cl_git_pass(git_repository_index(&index, g_repo));
460+
cl_git_pass(git_index_add_all(index, NULL, 0, NULL, NULL));
461+
462+
check_status(g_repo, 3, 0, 0, 0, 0, 0, 1, 0);
463+
464+
git_index_free(index);
465+
}
466+
467+
void test_index_addall__force_adds_ignored_directories(void)
468+
{
469+
git_index *index;
470+
471+
g_repo = cl_git_sandbox_init_new(TEST_DIR);
472+
473+
cl_git_mkfile(TEST_DIR "/file.foo", "a file");
474+
cl_git_mkfile(TEST_DIR "/file.bar", "another file");
475+
cl_must_pass(p_mkdir(TEST_DIR "/folder", 0777));
476+
cl_git_mkfile(TEST_DIR "/folder/asdf", "yet another file");
477+
478+
cl_git_mkfile(TEST_DIR "/.gitignore", "folder/\n");
479+
480+
check_status(g_repo, 0, 0, 0, 3, 0, 0, 1, 0);
481+
482+
cl_git_pass(git_repository_index(&index, g_repo));
483+
cl_git_pass(git_index_add_all(index, NULL, GIT_INDEX_ADD_FORCE, NULL, NULL));
484+
485+
check_status(g_repo, 4, 0, 0, 0, 0, 0, 0, 0);
486+
487+
git_index_free(index);
488+
}
489+
444490
void test_index_addall__adds_conflicts(void)
445491
{
446492
git_index *index;

0 commit comments

Comments
 (0)