diff --git a/src/libgit2/status.c b/src/libgit2/status.c index df0f7450731..771c90843f4 100644 --- a/src/libgit2/status.c +++ b/src/libgit2/status.c @@ -258,6 +258,14 @@ static int status_validate_options(const git_status_options *opts) return 0; } +static int is_ignored_delta(const git_vector *deltas, size_t idx, void *p) +{ + GIT_UNUSED(p); + git_diff_delta *delta = deltas->contents[idx]; + return delta->old_file.skip_worktree && delta->status == GIT_DELTA_DELETED; +} + + int git_status_list_new( git_status_list **out, git_repository *repo, @@ -355,6 +363,8 @@ int git_status_list_new( goto done; } + git_vector_remove_matching(&status->idx2wd->deltas, is_ignored_delta, NULL); + if ((flags & GIT_STATUS_OPT_RENAMES_INDEX_TO_WORKDIR) != 0 && (error = git_diff_find_similar(status->idx2wd, &findopt)) < 0) goto done; diff --git a/tests/libgit2/sparse/status.c b/tests/libgit2/sparse/status.c index fb77534ea89..c39df694d0b 100644 --- a/tests/libgit2/sparse/status.c +++ b/tests/libgit2/sparse/status.c @@ -1,6 +1,7 @@ #include "clar_libgit2.h" #include "futils.h" #include "git2/attr.h" +#include "attr_file.h" #include "sparse.h" #include "status/status_helpers.h" @@ -71,8 +72,6 @@ void test_sparse_status__cache_attr(void) git_sparse_checkout_init_options scopts = GIT_SPARSE_CHECKOUT_INIT_OPTIONS_INIT; g_repo = cl_git_sandbox_init("sparse"); - clar__skip(); - cl_git_pass(git_sparse_checkout_init(g_repo, &scopts)); git_attr_cache_flush(g_repo); @@ -227,6 +226,20 @@ void test_sparse_status__append_file(void) assert_checkout(one_test->expected, one_test->path); } +void test_sparse_status__reapply(void) +{ + status_entry_single st; + git_sparse_checkout_init_options scopts = GIT_SPARSE_CHECKOUT_INIT_OPTIONS_INIT; + g_repo = cl_git_sandbox_init("sparse"); + + cl_assert(git_fs_path_exists("sparse/file1")); + cl_assert(git_fs_path_exists("sparse/a/file3")); + + cl_git_pass(git_sparse_checkout_init(g_repo, &scopts)); + + cl_assert(git_fs_path_exists("sparse/file1")); + cl_assert(!git_fs_path_exists("sparse/a/file3")); +} void test_sparse_status__clean(void) { @@ -234,7 +247,9 @@ void test_sparse_status__clean(void) git_sparse_checkout_init_options scopts = GIT_SPARSE_CHECKOUT_INIT_OPTIONS_INIT; g_repo = cl_git_sandbox_init("sparse"); - clar__skip(); + memset(&st, 0, sizeof(st)); + cl_git_pass(git_status_foreach(g_repo, cb_status__single, &st)); + cl_assert_equal_i(0, st.count); cl_git_pass(git_sparse_checkout_init(g_repo, &scopts)); @@ -266,8 +281,6 @@ void test_sparse_status__new_file(void) git_sparse_checkout_init_options scopts = GIT_SPARSE_CHECKOUT_INIT_OPTIONS_INIT; g_repo = cl_git_sandbox_init("sparse"); - clar__skip(); - cl_git_pass(git_sparse_checkout_init(g_repo, &scopts)); cl_git_mkfile("sparse/newfile", "/hello world\n"); @@ -285,8 +298,6 @@ void test_sparse_status__new_file_new_folder(void) git_sparse_checkout_init_options scopts = GIT_SPARSE_CHECKOUT_INIT_OPTIONS_INIT; g_repo = cl_git_sandbox_init("sparse"); - clar__skip(); - cl_git_pass(git_sparse_checkout_init(g_repo, &scopts)); cl_must_pass(git_futils_mkdir("sparse/new", 0777, 0)); @@ -305,8 +316,6 @@ void test_sparse_status__new_file_sparse_folder(void) git_sparse_checkout_init_options scopts = GIT_SPARSE_CHECKOUT_INIT_OPTIONS_INIT; g_repo = cl_git_sandbox_init("sparse"); - clar__skip(); - cl_git_pass(git_sparse_checkout_init(g_repo, &scopts)); cl_must_pass(git_futils_mkdir("sparse/a", 0777, 0)); @@ -325,15 +334,13 @@ void test_sparse_status__new_sparse_file_sparse_folder(void) git_sparse_checkout_init_options scopts = GIT_SPARSE_CHECKOUT_INIT_OPTIONS_INIT; g_repo = cl_git_sandbox_init("sparse"); - clar__skip(); - cl_git_pass(git_sparse_checkout_init(g_repo, &scopts)); cl_must_pass(git_futils_mkdir("sparse/a", 0777, 0)); cl_git_mkfile("sparse/a/file3", "/hello world\n"); memset(&st, 0, sizeof(st)); cl_git_pass(git_status_foreach(g_repo, cb_status__single, &st)); - cl_assert_equal_i(0, st.count); + cl_assert_equal_i(1, st.count); refute_is_checkout("new/newfile"); }