static void *run_workdir_iterator(void *arg) { int error = 0; git_iterator *iter; const git_index_entry *entry = NULL; cl_git_pass(git_iterator_for_workdir( &iter, _repo, NULL, NULL, GIT_ITERATOR_DONT_AUTOEXPAND, NULL, NULL)); while (!error) { if (entry && entry->mode == GIT_FILEMODE_TREE) { error = git_iterator_advance_into(&entry, iter); if (error == GIT_ENOTFOUND) error = git_iterator_advance(&entry, iter); } else { error = git_iterator_advance(&entry, iter); } if (!error) (void)git_iterator_current_is_ignored(iter); } cl_assert_equal_i(GIT_ITEROVER, error); git_iterator_free(iter); giterr_clear(); return arg; }
static void workdir_iterator_test( const char *sandbox, const char *start, const char *end, int expected_count, int expected_ignores, const char **expected_names, const char *an_ignored_name) { git_iterator *i; const git_index_entry *entry; int count = 0, count_all = 0; git_repository *repo = cl_git_sandbox_init(sandbox); cl_git_pass(git_iterator_for_workdir_range(&i, repo, start, end)); cl_git_pass(git_iterator_current(i, &entry)); while (entry != NULL) { int ignored = git_iterator_current_is_ignored(i); if (S_ISDIR(entry->mode)) { cl_git_pass(git_iterator_advance_into_directory(i, &entry)); continue; } if (expected_names != NULL) cl_assert_equal_s(expected_names[count_all], entry->path); if (an_ignored_name && strcmp(an_ignored_name,entry->path)==0) cl_assert(ignored); if (!ignored) count++; count_all++; cl_git_pass(git_iterator_advance(i, &entry)); } git_iterator_free(i); cl_assert_equal_i(expected_count,count); cl_assert_equal_i(expected_count + expected_ignores, count_all); }
void test_diff_iterator__workdir_builtin_ignores(void) { git_repository *repo = cl_git_sandbox_init("attr"); git_iterator *i; git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT; const git_index_entry *entry; int idx; static struct { const char *path; bool ignored; } expected[] = { { "dir/", true }, { "file", false }, { "ign", true }, { "macro_bad", false }, { "macro_test", false }, { "root_test1", false }, { "root_test2", false }, { "root_test3", false }, { "root_test4.txt", false }, { "sub/", false }, { "sub/.gitattributes", false }, { "sub/abc", false }, { "sub/dir/", true }, { "sub/file", false }, { "sub/ign/", true }, { "sub/sub/", false }, { "sub/sub/.gitattributes", false }, { "sub/sub/dir", false }, /* file is not actually a dir */ { "sub/sub/file", false }, { NULL, false } }; cl_git_pass(p_mkdir("attr/sub/sub/.git", 0777)); cl_git_mkfile("attr/sub/.git", "whatever"); i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND; i_opts.start = "dir"; i_opts.end = "sub/sub/file"; cl_git_pass(git_iterator_for_workdir( &i, repo, NULL, NULL, &i_opts)); cl_git_pass(git_iterator_current(&entry, i)); for (idx = 0; entry != NULL; ++idx) { int ignored = git_iterator_current_is_ignored(i); cl_assert_equal_s(expected[idx].path, entry->path); cl_assert_(ignored == expected[idx].ignored, expected[idx].path); if (!ignored && (entry->mode == GIT_FILEMODE_TREE || entry->mode == GIT_FILEMODE_COMMIT)) { /* it is possible to advance "into" a submodule */ cl_git_pass(git_iterator_advance_into(&entry, i)); } else { int error = git_iterator_advance(&entry, i); cl_assert(!error || error == GIT_ITEROVER); } } cl_assert(expected[idx].path == NULL); git_iterator_free(i); }
static void workdir_iterator_test( const char *sandbox, const char *start, const char *end, int expected_count, int expected_ignores, const char **expected_names, const char *an_ignored_name) { git_iterator *i; git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT; const git_index_entry *entry; int error, count = 0, count_all = 0, count_all_post_reset = 0; git_repository *repo = cl_git_sandbox_init(sandbox); i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND; i_opts.start = start; i_opts.end = end; cl_git_pass(git_iterator_for_workdir(&i, repo, NULL, NULL, &i_opts)); error = git_iterator_current(&entry, i); cl_assert((error == 0 && entry != NULL) || (error == GIT_ITEROVER && entry == NULL)); while (entry != NULL) { int ignored = git_iterator_current_is_ignored(i); if (S_ISDIR(entry->mode)) { cl_git_pass(git_iterator_advance_into(&entry, i)); continue; } if (expected_names != NULL) cl_assert_equal_s(expected_names[count_all], entry->path); if (an_ignored_name && strcmp(an_ignored_name,entry->path)==0) cl_assert(ignored); if (!ignored) count++; count_all++; error = git_iterator_advance(&entry, i); cl_assert((error == 0 && entry != NULL) || (error == GIT_ITEROVER && entry == NULL)); } cl_assert_equal_i(expected_count, count); cl_assert_equal_i(expected_count + expected_ignores, count_all); cl_git_pass(git_iterator_reset(i, NULL, NULL)); error = git_iterator_current(&entry, i); cl_assert((error == 0 && entry != NULL) || (error == GIT_ITEROVER && entry == NULL)); while (entry != NULL) { if (S_ISDIR(entry->mode)) { cl_git_pass(git_iterator_advance_into(&entry, i)); continue; } if (expected_names != NULL) cl_assert_equal_s( expected_names[count_all_post_reset], entry->path); count_all_post_reset++; error = git_iterator_advance(&entry, i); cl_assert(error == 0 || error == GIT_ITEROVER); } cl_assert_equal_i(count_all, count_all_post_reset); git_iterator_free(i); }
static int checkout_action_wd_only( checkout_data *data, git_iterator *workdir, const git_index_entry *wd, git_vector *pathspec) { bool remove = false; git_checkout_notify_t notify = GIT_CHECKOUT_NOTIFY_NONE; if (!git_pathspec_match_path( pathspec, wd->path, (data->strategy & GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH) != 0, git_iterator_ignore_case(workdir), NULL)) return 0; /* check if item is tracked in the index but not in the checkout diff */ if (data->index != NULL) { if (wd->mode != GIT_FILEMODE_TREE) { int error; if ((error = git_index_find(NULL, data->index, wd->path)) == 0) { notify = GIT_CHECKOUT_NOTIFY_DIRTY; remove = ((data->strategy & GIT_CHECKOUT_FORCE) != 0); } else if (error != GIT_ENOTFOUND) return error; } else { /* for tree entries, we have to see if there are any index * entries that are contained inside that tree */ size_t pos = git_index__prefix_position(data->index, wd->path); const git_index_entry *e = git_index_get_byindex(data->index, pos); if (e != NULL && data->diff->pfxcomp(e->path, wd->path) == 0) { notify = GIT_CHECKOUT_NOTIFY_DIRTY; remove = ((data->strategy & GIT_CHECKOUT_FORCE) != 0); } } } if (notify != GIT_CHECKOUT_NOTIFY_NONE) /* found in index */; else if (git_iterator_current_is_ignored(workdir)) { notify = GIT_CHECKOUT_NOTIFY_IGNORED; remove = ((data->strategy & GIT_CHECKOUT_REMOVE_IGNORED) != 0); } else { notify = GIT_CHECKOUT_NOTIFY_UNTRACKED; remove = ((data->strategy & GIT_CHECKOUT_REMOVE_UNTRACKED) != 0); } if (checkout_notify(data, notify, NULL, wd)) return GIT_EUSER; if (remove) { char *path = git_pool_strdup(&data->pool, wd->path); GITERR_CHECK_ALLOC(path); if (git_vector_insert(&data->removes, path) < 0) return -1; } return 0; }