Exemple #1
0
void test_repo_iterator__treefilelist(void)
{
	git_iterator *i;
	git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT;
	git_vector filelist;
	git_tree *tree;
	bool default_icase;
	int expect;

	cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb));
	cl_git_pass(git_vector_insert(&filelist, "a"));
	cl_git_pass(git_vector_insert(&filelist, "B"));
	cl_git_pass(git_vector_insert(&filelist, "c"));
	cl_git_pass(git_vector_insert(&filelist, "D"));
	cl_git_pass(git_vector_insert(&filelist, "e"));
	cl_git_pass(git_vector_insert(&filelist, "k.a"));
	cl_git_pass(git_vector_insert(&filelist, "k.b"));
	cl_git_pass(git_vector_insert(&filelist, "k/1"));
	cl_git_pass(git_vector_insert(&filelist, "k/a"));
	cl_git_pass(git_vector_insert(&filelist, "kZZZZZZZ"));
	cl_git_pass(git_vector_insert(&filelist, "L/1"));

	g_repo = cl_git_sandbox_init("icase");
	git_repository_head_tree(&tree, g_repo);

	/* All indexfilelist iterator tests are "autoexpand with no tree entries" */
	/* In this test we DO NOT force a case on the iteratords and verify default behavior. */

	i_opts.pathlist.strings = (char **)filelist.contents;
	i_opts.pathlist.count = filelist.length;

	cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
	expect_iterator_items(i, 8, NULL, 8, NULL);
	git_iterator_free(i);

	i_opts.start = "c";
	i_opts.end = NULL;
	cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
	default_icase = git_iterator_ignore_case(i);
	/* (c D e k/1 k/a L ==> 6) vs (c e k/1 k/a ==> 4) */
	expect = ((default_icase) ? 6 : 4);
	expect_iterator_items(i, expect, NULL, expect, NULL);
	git_iterator_free(i);

	i_opts.start = NULL;
	i_opts.end = "e";
	cl_git_pass(git_iterator_for_tree(&i, tree, &i_opts));
	default_icase = git_iterator_ignore_case(i);
	/* (a B c D e ==> 5) vs (B D L/1 a c e ==> 6) */
	expect = ((default_icase) ? 5 : 6);
	expect_iterator_items(i, expect, NULL, expect, NULL);
	git_iterator_free(i);

	git_vector_free(&filelist);
	git_tree_free(tree);
}
Exemple #2
0
static void check_index_range(
	git_repository *repo,
	const char *start,
	const char *end,
	bool ignore_case,
	int expected_count)
{
	git_index *index;
	git_iterator *i;
	int error, count, caps;
	bool is_ignoring_case;

	cl_git_pass(git_repository_index(&index, repo));

	caps = git_index_caps(index);
	is_ignoring_case = ((caps & GIT_INDEXCAP_IGNORE_CASE) != 0);

	if (ignore_case != is_ignoring_case)
		cl_git_pass(git_index_set_caps(index, caps ^ GIT_INDEXCAP_IGNORE_CASE));

	cl_git_pass(git_iterator_for_index(&i, index, 0, start, end));

	cl_assert(git_iterator_ignore_case(i) == ignore_case);

	for (count = 0; !(error = git_iterator_advance(NULL, i)); ++count)
		/* count em up */;

	cl_assert_equal_i(GIT_ITEROVER, error);
	cl_assert_equal_i(expected_count, count);

	git_iterator_free(i);
	git_index_free(index);
}
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;
}