Skip to content

Commit 402a587

Browse files
authored
Filter out skip_worktree statuses
1 parent 6bae1dc commit 402a587

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

src/libgit2/status.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,14 @@ static int status_validate_options(const git_status_options *opts)
258258
return 0;
259259
}
260260

261+
static int is_ignored_delta(const git_vector *deltas, size_t idx, void *p)
262+
{
263+
GIT_UNUSED(p);
264+
git_diff_delta *delta = deltas->contents[idx];
265+
return delta->old_file.skip_worktree && delta->status == GIT_DELTA_DELETED;
266+
}
267+
268+
261269
int git_status_list_new(
262270
git_status_list **out,
263271
git_repository *repo,
@@ -355,6 +363,8 @@ int git_status_list_new(
355363
goto done;
356364
}
357365

366+
git_vector_remove_matching(&status->idx2wd->deltas, is_ignored_delta, NULL);
367+
358368
if ((flags & GIT_STATUS_OPT_RENAMES_INDEX_TO_WORKDIR) != 0 &&
359369
(error = git_diff_find_similar(status->idx2wd, &findopt)) < 0)
360370
goto done;

tests/libgit2/sparse/status.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "clar_libgit2.h"
22
#include "futils.h"
33
#include "git2/attr.h"
4+
#include "attr_file.h"
45
#include "sparse.h"
56
#include "status/status_helpers.h"
67

@@ -71,8 +72,6 @@ void test_sparse_status__cache_attr(void)
7172
git_sparse_checkout_init_options scopts = GIT_SPARSE_CHECKOUT_INIT_OPTIONS_INIT;
7273
g_repo = cl_git_sandbox_init("sparse");
7374

74-
clar__skip();
75-
7675
cl_git_pass(git_sparse_checkout_init(g_repo, &scopts));
7776

7877
git_attr_cache_flush(g_repo);
@@ -227,14 +226,30 @@ void test_sparse_status__append_file(void)
227226
assert_checkout(one_test->expected, one_test->path);
228227
}
229228

229+
void test_sparse_status__reapply(void)
230+
{
231+
status_entry_single st;
232+
git_sparse_checkout_init_options scopts = GIT_SPARSE_CHECKOUT_INIT_OPTIONS_INIT;
233+
g_repo = cl_git_sandbox_init("sparse");
234+
235+
cl_assert(git_fs_path_exists("sparse/file1"));
236+
cl_assert(git_fs_path_exists("sparse/a/file3"));
237+
238+
cl_git_pass(git_sparse_checkout_init(g_repo, &scopts));
239+
240+
cl_assert(git_fs_path_exists("sparse/file1"));
241+
cl_assert(!git_fs_path_exists("sparse/a/file3"));
242+
}
230243

231244
void test_sparse_status__clean(void)
232245
{
233246
status_entry_single st;
234247
git_sparse_checkout_init_options scopts = GIT_SPARSE_CHECKOUT_INIT_OPTIONS_INIT;
235248
g_repo = cl_git_sandbox_init("sparse");
236249

237-
clar__skip();
250+
memset(&st, 0, sizeof(st));
251+
cl_git_pass(git_status_foreach(g_repo, cb_status__single, &st));
252+
cl_assert_equal_i(0, st.count);
238253

239254
cl_git_pass(git_sparse_checkout_init(g_repo, &scopts));
240255

@@ -266,8 +281,6 @@ void test_sparse_status__new_file(void)
266281
git_sparse_checkout_init_options scopts = GIT_SPARSE_CHECKOUT_INIT_OPTIONS_INIT;
267282
g_repo = cl_git_sandbox_init("sparse");
268283

269-
clar__skip();
270-
271284
cl_git_pass(git_sparse_checkout_init(g_repo, &scopts));
272285

273286
cl_git_mkfile("sparse/newfile", "/hello world\n");
@@ -285,8 +298,6 @@ void test_sparse_status__new_file_new_folder(void)
285298
git_sparse_checkout_init_options scopts = GIT_SPARSE_CHECKOUT_INIT_OPTIONS_INIT;
286299
g_repo = cl_git_sandbox_init("sparse");
287300

288-
clar__skip();
289-
290301
cl_git_pass(git_sparse_checkout_init(g_repo, &scopts));
291302

292303
cl_must_pass(git_futils_mkdir("sparse/new", 0777, 0));
@@ -305,8 +316,6 @@ void test_sparse_status__new_file_sparse_folder(void)
305316
git_sparse_checkout_init_options scopts = GIT_SPARSE_CHECKOUT_INIT_OPTIONS_INIT;
306317
g_repo = cl_git_sandbox_init("sparse");
307318

308-
clar__skip();
309-
310319
cl_git_pass(git_sparse_checkout_init(g_repo, &scopts));
311320

312321
cl_must_pass(git_futils_mkdir("sparse/a", 0777, 0));
@@ -325,15 +334,13 @@ void test_sparse_status__new_sparse_file_sparse_folder(void)
325334
git_sparse_checkout_init_options scopts = GIT_SPARSE_CHECKOUT_INIT_OPTIONS_INIT;
326335
g_repo = cl_git_sandbox_init("sparse");
327336

328-
clar__skip();
329-
330337
cl_git_pass(git_sparse_checkout_init(g_repo, &scopts));
331338

332339
cl_must_pass(git_futils_mkdir("sparse/a", 0777, 0));
333340
cl_git_mkfile("sparse/a/file3", "/hello world\n");
334341
memset(&st, 0, sizeof(st));
335342
cl_git_pass(git_status_foreach(g_repo, cb_status__single, &st));
336-
cl_assert_equal_i(0, st.count);
343+
cl_assert_equal_i(1, st.count);
337344

338345
refute_is_checkout("new/newfile");
339346
}

0 commit comments

Comments
 (0)