void test_iterator_workdir__depth(void) { git_iterator *iter; git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT; g_repo = cl_git_sandbox_init("icase"); build_workdir_tree("icase", 10, 10); build_workdir_tree("icase/DIR01/sUB01", 50, 0); build_workdir_tree("icase/dir02/sUB01", 50, 0); /* auto expand with no tree entries */ cl_git_pass(git_iterator_for_workdir(&iter, g_repo, NULL, NULL, &iter_opts)); expect_iterator_items(iter, 125, NULL, 125, NULL); git_iterator_free(iter); /* auto expand with tree entries (empty dirs silently skipped) */ iter_opts.flags = GIT_ITERATOR_INCLUDE_TREES; cl_git_pass(git_iterator_for_workdir(&iter, g_repo, NULL, NULL, &iter_opts)); expect_iterator_items(iter, 337, NULL, 337, NULL); git_iterator_free(iter); }
static int commit_worktree( git_oid *w_commit_oid, git_index *index, const git_signature *stasher, const char *message, git_commit *i_commit, git_commit *b_commit, git_commit *u_commit) { int error = 0; git_tree *w_tree = NULL, *i_tree = NULL; const git_commit *parents[] = { NULL, NULL, NULL }; parents[0] = b_commit; parents[1] = i_commit; parents[2] = u_commit; if ((error = git_commit_tree(&i_tree, i_commit)) < 0) goto cleanup; if ((error = git_index_read_tree(index, i_tree)) < 0) goto cleanup; if ((error = build_workdir_tree(&w_tree, index, b_commit)) < 0) goto cleanup; error = git_commit_create( w_commit_oid, git_index_owner(index), NULL, stasher, stasher, NULL, message, w_tree, u_commit ? 3 : 2, parents); cleanup: git_tree_free(i_tree); git_tree_free(w_tree); return error; }
/* The filesystem iterator is a workdir iterator without any special * workdir handling capabilities (ignores, submodules, etc). */ void test_iterator_workdir__filesystem(void) { git_iterator *i; git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT; static const char *expect_base[] = { "DIR01/Sub02/file", "DIR01/sub00/file", "current_file", "dir00/Sub02/file", "dir00/file", "dir00/sub00/file", "modified_file", "new_file", NULL, }; static const char *expect_trees[] = { "DIR01/", "DIR01/SUB03/", "DIR01/Sub02/", "DIR01/Sub02/file", "DIR01/sUB01/", "DIR01/sub00/", "DIR01/sub00/file", "current_file", "dir00/", "dir00/SUB03/", "dir00/Sub02/", "dir00/Sub02/file", "dir00/file", "dir00/sUB01/", "dir00/sub00/", "dir00/sub00/file", "modified_file", "new_file", NULL, }; static const char *expect_noauto[] = { "DIR01/", "current_file", "dir00/", "modified_file", "new_file", NULL, }; g_repo = cl_git_sandbox_init("status"); build_workdir_tree("status/subdir", 2, 4); cl_git_pass(git_iterator_for_filesystem(&i, "status/subdir", NULL)); expect_iterator_items(i, 8, expect_base, 8, expect_base); git_iterator_free(i); i_opts.flags = GIT_ITERATOR_INCLUDE_TREES; cl_git_pass(git_iterator_for_filesystem(&i, "status/subdir", &i_opts)); expect_iterator_items(i, 18, expect_trees, 18, expect_trees); git_iterator_free(i); i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND; cl_git_pass(git_iterator_for_filesystem(&i, "status/subdir", &i_opts)); expect_iterator_items(i, 5, expect_noauto, 18, expect_trees); git_iterator_free(i); git__tsort((void **)expect_base, 8, (git__tsort_cmp)git__strcasecmp); git__tsort((void **)expect_trees, 18, (git__tsort_cmp)git__strcasecmp); git__tsort((void **)expect_noauto, 5, (git__tsort_cmp)git__strcasecmp); i_opts.flags = GIT_ITERATOR_IGNORE_CASE; cl_git_pass(git_iterator_for_filesystem(&i, "status/subdir", &i_opts)); expect_iterator_items(i, 8, expect_base, 8, expect_base); git_iterator_free(i); i_opts.flags = GIT_ITERATOR_IGNORE_CASE | GIT_ITERATOR_INCLUDE_TREES; cl_git_pass(git_iterator_for_filesystem(&i, "status/subdir", &i_opts)); expect_iterator_items(i, 18, expect_trees, 18, expect_trees); git_iterator_free(i); i_opts.flags = GIT_ITERATOR_IGNORE_CASE | GIT_ITERATOR_DONT_AUTOEXPAND; cl_git_pass(git_iterator_for_filesystem(&i, "status/subdir", &i_opts)); expect_iterator_items(i, 5, expect_noauto, 18, expect_trees); git_iterator_free(i); }