Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter out skip_worktree statuses #42

Merged
merged 7 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/libgit2/status.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
31 changes: 19 additions & 12 deletions tests/libgit2/sparse/status.c
Original file line number Diff line number Diff line change
@@ -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"

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -227,14 +226,30 @@ 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)
{
status_entry_single st;
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));

Expand Down Expand Up @@ -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");
Expand All @@ -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));
Expand All @@ -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));
Expand All @@ -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");
}
Expand Down
Loading