static void index_iterator_test( const char *sandbox, const char *start, const char *end, git_iterator_flag_t flags, int expected_count, const char **expected_names, const char **expected_oids) { git_index *index; git_iterator *i; const git_index_entry *entry; int error, count = 0, caps; git_repository *repo = cl_git_sandbox_init(sandbox); git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT; cl_git_pass(git_repository_index(&index, repo)); caps = git_index_caps(index); iter_opts.flags = flags; iter_opts.start = start; iter_opts.end = end; cl_git_pass(git_iterator_for_index(&i, repo, index, &iter_opts)); while (!(error = git_iterator_advance(&entry, i))) { cl_assert(entry); if (expected_names != NULL) cl_assert_equal_s(expected_names[count], entry->path); if (expected_oids != NULL) { git_oid oid; cl_git_pass(git_oid_fromstr(&oid, expected_oids[count])); cl_assert_equal_oid(&oid, &entry->id); } count++; } cl_assert_equal_i(GIT_ITEROVER, error); cl_assert(!entry); cl_assert_equal_i(expected_count, count); git_iterator_free(i); cl_assert(caps == git_index_caps(index)); git_index_free(index); }
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); }
void test_index_reuc__ignore_case(void) { const git_index_reuc_entry *reuc; git_oid oid; int index_caps; index_caps = git_index_caps(repo_index); index_caps &= ~GIT_INDEXCAP_IGNORE_CASE; cl_git_pass(git_index_set_caps(repo_index, index_caps)); cl_assert(!git_index_reuc_get_bypath(repo_index, "TWO.txt")); index_caps |= GIT_INDEXCAP_IGNORE_CASE; cl_git_pass(git_index_set_caps(repo_index, index_caps)); cl_assert_equal_i(2, git_index_reuc_entrycount(repo_index)); cl_assert(reuc = git_index_reuc_get_bypath(repo_index, "TWO.txt")); cl_assert(strcmp(reuc->path, "two.txt") == 0); cl_assert(reuc->mode[0] == 0100644); cl_assert(reuc->mode[1] == 0100644); cl_assert(reuc->mode[2] == 0100644); git_oid_fromstr(&oid, TWO_ANCESTOR_OID); cl_assert(git_oid_cmp(&reuc->oid[0], &oid) == 0); git_oid_fromstr(&oid, TWO_OUR_OID); cl_assert(git_oid_cmp(&reuc->oid[1], &oid) == 0); git_oid_fromstr(&oid, TWO_THEIR_OID); cl_assert(git_oid_cmp(&reuc->oid[2], &oid) == 0); }
void test_repo_iterator__indexfilelist(void) { git_iterator *i; git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT; git_index *index; git_vector filelist; int 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/1")); cl_git_pass(git_vector_insert(&filelist, "k/a")); cl_git_pass(git_vector_insert(&filelist, "L/1")); g_repo = cl_git_sandbox_init("icase"); cl_git_pass(git_repository_index(&index, g_repo)); /* In this test we DO NOT force a case setting on the index. */ default_icase = ((git_index_caps(index) & GIT_INDEXCAP_IGNORE_CASE) != 0); i_opts.pathlist.strings = (char **)filelist.contents; i_opts.pathlist.count = filelist.length; /* All indexfilelist iterator tests are "autoexpand with no tree entries" */ cl_git_pass(git_iterator_for_index(&i, index, &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_index(&i, index, &i_opts)); /* (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_index(&i, index, &i_opts)); /* (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_index_free(index); git_vector_free(&filelist); }
void test_status_ignore__ignore_pattern_ignorecase(void) { unsigned int flags; bool ignore_case; git_index *index; g_repo = cl_git_sandbox_init("empty_standard_repo"); cl_git_rewritefile("empty_standard_repo/.gitignore", "a.txt\n"); cl_git_mkfile("empty_standard_repo/A.txt", "Differs in case"); cl_git_pass(git_repository_index(&index, g_repo)); ignore_case = (git_index_caps(index) & GIT_INDEXCAP_IGNORE_CASE) != 0; git_index_free(index); cl_git_pass(git_status_file(&flags, g_repo, "A.txt")); cl_assert(flags == ignore_case ? GIT_STATUS_IGNORED : GIT_STATUS_WT_NEW); }
void test_index_tests__reload_while_ignoring_case(void) { git_index *index; unsigned int caps; cl_git_pass(git_index_open(&index, TEST_INDEX_PATH)); cl_git_pass(git_vector_verify_sorted(&index->entries)); caps = git_index_caps(index); cl_git_pass(git_index_set_caps(index, caps &= ~GIT_INDEXCAP_IGNORE_CASE)); cl_git_pass(git_index_read(index, true)); cl_git_pass(git_vector_verify_sorted(&index->entries)); cl_git_pass(git_index_set_caps(index, caps | GIT_INDEXCAP_IGNORE_CASE)); cl_git_pass(git_index_read(index, true)); cl_git_pass(git_vector_verify_sorted(&index->entries)); git_index_free(index); }
void test_index_filemodes__trusted(void) { git_index *index; /* Only run these tests on platforms where I can actually * chmod a file and get the stat results I expect! */ if (!cl_is_chmod_supported()) return; cl_repo_set_bool(g_repo, "core.filemode", true); cl_git_pass(git_repository_index(&index, g_repo)); cl_assert((git_index_caps(index) & GIT_INDEXCAP_NO_FILEMODE) == 0); /* 1 - add 0644 over existing 0644 -> expect 0644 */ replace_file_with_mode("exec_off", "filemodes/exec_off.0", 0644); add_and_check_mode(index, "exec_off", GIT_FILEMODE_BLOB); /* 2 - add 0644 over existing 0755 -> expect 0644 */ replace_file_with_mode("exec_on", "filemodes/exec_on.0", 0644); add_and_check_mode(index, "exec_on", GIT_FILEMODE_BLOB); /* 3 - add 0755 over existing 0644 -> expect 0755 */ replace_file_with_mode("exec_off", "filemodes/exec_off.1", 0755); add_and_check_mode(index, "exec_off", GIT_FILEMODE_BLOB_EXECUTABLE); /* 4 - add 0755 over existing 0755 -> expect 0755 */ replace_file_with_mode("exec_on", "filemodes/exec_on.1", 0755); add_and_check_mode(index, "exec_on", GIT_FILEMODE_BLOB_EXECUTABLE); /* 5 - add new 0644 -> expect 0644 */ cl_git_write2file("filemodes/new_off", "blah", 0, O_WRONLY | O_CREAT | O_TRUNC, 0644); add_and_check_mode(index, "new_off", GIT_FILEMODE_BLOB); /* 6 - add 0755 -> expect 0755 */ cl_git_write2file("filemodes/new_on", "blah", 0, O_WRONLY | O_CREAT | O_TRUNC, 0755); add_and_check_mode(index, "new_on", GIT_FILEMODE_BLOB_EXECUTABLE); git_index_free(index); }
void test_index_tests__preserves_case(void) { git_repository *repo; git_index *index; const git_index_entry *entry; int index_caps; cl_set_cleanup(&cleanup_myrepo, NULL); cl_git_pass(git_repository_init(&repo, "./myrepo", 0)); cl_git_pass(git_repository_index(&index, repo)); index_caps = git_index_caps(index); cl_git_rewritefile("myrepo/test.txt", "hey there\n"); cl_git_pass(git_index_add_bypath(index, "test.txt")); cl_git_pass(p_rename("myrepo/test.txt", "myrepo/TEST.txt")); cl_git_rewritefile("myrepo/TEST.txt", "hello again\n"); cl_git_pass(git_index_add_bypath(index, "TEST.txt")); if (index_caps & GIT_INDEXCAP_IGNORE_CASE) cl_assert_equal_i(1, (int)git_index_entrycount(index)); else cl_assert_equal_i(2, (int)git_index_entrycount(index)); /* Test access by path instead of index */ cl_assert((entry = git_index_get_bypath(index, "test.txt", 0)) != NULL); /* The path should *not* have changed without an explicit remove */ cl_assert(git__strcmp(entry->path, "test.txt") == 0); cl_assert((entry = git_index_get_bypath(index, "TEST.txt", 0)) != NULL); if (index_caps & GIT_INDEXCAP_IGNORE_CASE) /* The path should *not* have changed without an explicit remove */ cl_assert(git__strcmp(entry->path, "test.txt") == 0); else cl_assert(git__strcmp(entry->path, "TEST.txt") == 0); git_index_free(index); git_repository_free(repo); }
void test_repo_iterator__indexfilelist_4(void) { git_iterator *i; git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT; git_index *index; git_vector filelist = GIT_VECTOR_INIT; int default_icase, expect; g_repo = cl_git_sandbox_init("icase"); cl_git_pass(git_repository_index(&index, g_repo)); cl_git_pass(git_vector_init(&filelist, 100, &git__strcmp_cb)); cl_git_pass(git_vector_insert(&filelist, "0")); 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")); 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, "kZZZZZZZ")); /* In this test we DO NOT force a case setting on the index. */ default_icase = ((git_index_caps(index) & GIT_INDEXCAP_IGNORE_CASE) != 0); i_opts.pathlist.strings = (char **)filelist.contents; i_opts.pathlist.count = filelist.length; i_opts.start = "b"; i_opts.end = "k/D"; /* (c D e k/1 k/a k/B k/c k/D) vs (c e k/1 k/B k/D) */ expect = default_icase ? 8 : 5; cl_git_pass(git_iterator_for_index(&i, index, &i_opts)); expect_iterator_items(i, expect, NULL, expect, NULL); git_iterator_free(i); git_index_free(index); git_vector_free(&filelist); }
void test_index_reuc__updates_existing(void) { const git_index_reuc_entry *reuc; git_oid ancestor_oid, our_oid, their_oid, oid; int index_caps; git_index_clear(repo_index); index_caps = git_index_caps(repo_index); index_caps |= GIT_INDEXCAP_IGNORE_CASE; cl_git_pass(git_index_set_caps(repo_index, index_caps)); git_oid_fromstr(&ancestor_oid, TWO_ANCESTOR_OID); git_oid_fromstr(&our_oid, TWO_OUR_OID); git_oid_fromstr(&their_oid, TWO_THEIR_OID); cl_git_pass(git_index_reuc_add(repo_index, "two.txt", 0100644, &ancestor_oid, 0100644, &our_oid, 0100644, &their_oid)); cl_git_pass(git_index_reuc_add(repo_index, "TWO.txt", 0100644, &our_oid, 0100644, &their_oid, 0100644, &ancestor_oid)); cl_assert_equal_i(1, git_index_reuc_entrycount(repo_index)); cl_assert(reuc = git_index_reuc_get_byindex(repo_index, 0)); cl_assert(strcmp(reuc->path, "TWO.txt") == 0); git_oid_fromstr(&oid, TWO_OUR_OID); cl_assert(git_oid_cmp(&reuc->oid[0], &oid) == 0); git_oid_fromstr(&oid, TWO_THEIR_OID); cl_assert(git_oid_cmp(&reuc->oid[1], &oid) == 0); git_oid_fromstr(&oid, TWO_ANCESTOR_OID); cl_assert(git_oid_cmp(&reuc->oid[2], &oid) == 0); }
/* this test is similar to t18-status.c:statuscb3 */ void test_status_worktree__swap_subdir_and_file(void) { status_entry_counts counts; git_repository *repo = cl_git_sandbox_init("status"); git_index *index; git_status_options opts = GIT_STATUS_OPTIONS_INIT; bool ignore_case; cl_git_pass(git_repository_index(&index, repo)); ignore_case = (git_index_caps(index) & GIT_INDEXCAP_IGNORE_CASE) != 0; git_index_free(index); /* first alter the contents of the worktree */ cl_git_pass(p_rename("status/current_file", "status/swap")); cl_git_pass(p_rename("status/subdir", "status/current_file")); cl_git_pass(p_rename("status/swap", "status/subdir")); cl_git_mkfile("status/.HEADER", "dummy"); cl_git_mkfile("status/42-is-not-prime.sigh", "dummy"); cl_git_mkfile("status/README.md", "dummy"); /* now get status */ memset(&counts, 0x0, sizeof(status_entry_counts)); counts.expected_entry_count = entry_count3; counts.expected_paths = ignore_case ? entry_paths3_icase : entry_paths3; counts.expected_statuses = ignore_case ? entry_statuses3_icase : entry_statuses3; opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_INCLUDE_IGNORED; cl_git_pass( git_status_foreach_ext(repo, &opts, cb_status__normal, &counts) ); cl_assert_equal_i(counts.expected_entry_count, counts.entry_count); cl_assert_equal_i(0, counts.wrong_status_flags_count); cl_assert_equal_i(0, counts.wrong_sorted_path); }
void test_index_filemodes__untrusted(void) { git_index *index; cl_repo_set_bool(g_repo, "core.filemode", false); cl_git_pass(git_repository_index(&index, g_repo)); cl_assert((git_index_caps(index) & GIT_INDEXCAP_NO_FILEMODE) != 0); /* 1 - add 0644 over existing 0644 -> expect 0644 */ replace_file_with_mode("exec_off", "filemodes/exec_off.0", 0644); add_and_check_mode(index, "exec_off", GIT_FILEMODE_BLOB); /* 2 - add 0644 over existing 0755 -> expect 0755 */ replace_file_with_mode("exec_on", "filemodes/exec_on.0", 0644); add_and_check_mode(index, "exec_on", GIT_FILEMODE_BLOB_EXECUTABLE); /* 3 - add 0755 over existing 0644 -> expect 0644 */ replace_file_with_mode("exec_off", "filemodes/exec_off.1", 0755); add_and_check_mode(index, "exec_off", GIT_FILEMODE_BLOB); /* 4 - add 0755 over existing 0755 -> expect 0755 */ replace_file_with_mode("exec_on", "filemodes/exec_on.1", 0755); add_and_check_mode(index, "exec_on", GIT_FILEMODE_BLOB_EXECUTABLE); /* 5 - add new 0644 -> expect 0644 */ cl_git_write2file("filemodes/new_off", "blah", 0, O_WRONLY | O_CREAT | O_TRUNC, 0644); add_and_check_mode(index, "new_off", GIT_FILEMODE_BLOB); /* 6 - add new 0755 -> expect 0644 if core.filemode == false */ cl_git_write2file("filemodes/new_on", "blah", 0, O_WRONLY | O_CREAT | O_TRUNC, 0755); add_and_check_mode(index, "new_on", GIT_FILEMODE_BLOB); git_index_free(index); }
void test_status_worktree__sorting_by_case(void) { git_repository *repo = cl_git_sandbox_init("icase"); git_index *index; git_status_options opts = GIT_STATUS_OPTIONS_INIT; bool native_ignore_case; status_entry_counts counts; cl_git_pass(git_repository_index(&index, repo)); native_ignore_case = (git_index_caps(index) & GIT_INDEXCAP_IGNORE_CASE) != 0; git_index_free(index); memset(&counts, 0, sizeof(counts)); counts.expected_entry_count = 0; counts.expected_paths = NULL; counts.expected_statuses = NULL; cl_git_pass( git_status_foreach_ext(repo, &opts, cb_status__normal, &counts)); cl_assert_equal_i(counts.expected_entry_count, counts.entry_count); cl_assert_equal_i(0, counts.wrong_status_flags_count); cl_assert_equal_i(0, counts.wrong_sorted_path); cl_git_rewritefile("icase/B", "new stuff"); cl_must_pass(p_unlink("icase/c")); cl_git_rewritefile("icase/g", "new stuff"); cl_must_pass(p_unlink("icase/H")); memset(&counts, 0, sizeof(counts)); counts.expected_entry_count = 4; if (native_ignore_case) { counts.expected_paths = icase_paths; counts.expected_statuses = icase_statuses; } else { counts.expected_paths = case_paths; counts.expected_statuses = case_statuses; } cl_git_pass( git_status_foreach_ext(repo, &opts, cb_status__normal, &counts)); cl_assert_equal_i(counts.expected_entry_count, counts.entry_count); cl_assert_equal_i(0, counts.wrong_status_flags_count); cl_assert_equal_i(0, counts.wrong_sorted_path); opts.flags = GIT_STATUS_OPT_SORT_CASE_SENSITIVELY; memset(&counts, 0, sizeof(counts)); counts.expected_entry_count = 4; counts.expected_paths = case_paths; counts.expected_statuses = case_statuses; cl_git_pass( git_status_foreach_ext(repo, &opts, cb_status__normal, &counts)); cl_assert_equal_i(counts.expected_entry_count, counts.entry_count); cl_assert_equal_i(0, counts.wrong_status_flags_count); cl_assert_equal_i(0, counts.wrong_sorted_path); opts.flags = GIT_STATUS_OPT_SORT_CASE_INSENSITIVELY; memset(&counts, 0, sizeof(counts)); counts.expected_entry_count = 4; counts.expected_paths = icase_paths; counts.expected_statuses = icase_statuses; cl_git_pass( git_status_foreach_ext(repo, &opts, cb_status__normal, &counts)); cl_assert_equal_i(counts.expected_entry_count, counts.entry_count); cl_assert_equal_i(0, counts.wrong_status_flags_count); cl_assert_equal_i(0, counts.wrong_sorted_path); }
void test_repo_iterator__indexfilelist_icase(void) { git_iterator *i; git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT; git_index *index; int caps; git_vector filelist; 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/1")); cl_git_pass(git_vector_insert(&filelist, "k/a")); cl_git_pass(git_vector_insert(&filelist, "L/1")); g_repo = cl_git_sandbox_init("icase"); cl_git_pass(git_repository_index(&index, g_repo)); caps = git_index_caps(index); /* force case sensitivity */ cl_git_pass(git_index_set_caps(index, caps & ~GIT_INDEXCAP_IGNORE_CASE)); /* All indexfilelist iterator tests are "autoexpand with no tree entries" */ i_opts.pathlist.strings = (char **)filelist.contents; i_opts.pathlist.count = filelist.length; i_opts.start = "c"; i_opts.end = "k/D"; cl_git_pass(git_iterator_for_index(&i, index, &i_opts)); expect_iterator_items(i, 3, NULL, 3, NULL); git_iterator_free(i); i_opts.start = "k"; i_opts.end = "k/Z"; cl_git_pass(git_iterator_for_index(&i, index, &i_opts)); expect_iterator_items(i, 1, NULL, 1, NULL); git_iterator_free(i); /* force case insensitivity */ cl_git_pass(git_index_set_caps(index, caps | GIT_INDEXCAP_IGNORE_CASE)); i_opts.start = "c"; i_opts.end = "k/D"; cl_git_pass(git_iterator_for_index(&i, index, &i_opts)); expect_iterator_items(i, 5, NULL, 5, NULL); git_iterator_free(i); i_opts.start = "k"; i_opts.end = "k/Z"; cl_git_pass(git_iterator_for_index(&i, index, &i_opts)); expect_iterator_items(i, 2, NULL, 2, NULL); git_iterator_free(i); cl_git_pass(git_index_set_caps(index, caps)); git_index_free(index); git_vector_free(&filelist); }
void test_repo_iterator__index_icase(void) { git_iterator *i; git_iterator_options i_opts = GIT_ITERATOR_OPTIONS_INIT; git_index *index; int caps; g_repo = cl_git_sandbox_init("icase"); cl_git_pass(git_repository_index(&index, g_repo)); caps = git_index_caps(index); /* force case sensitivity */ cl_git_pass(git_index_set_caps(index, caps & ~GIT_INDEXCAP_IGNORE_CASE)); /* autoexpand with no tree entries over range */ i_opts.start = "c"; i_opts.end = "k/D"; cl_git_pass(git_iterator_for_index(&i, index, &i_opts)); expect_iterator_items(i, 7, NULL, 7, NULL); git_iterator_free(i); i_opts.start = "k"; i_opts.end = "k/Z"; cl_git_pass(git_iterator_for_index(&i, index, &i_opts)); expect_iterator_items(i, 3, NULL, 3, NULL); git_iterator_free(i); /* auto expand with tree entries */ i_opts.flags = GIT_ITERATOR_INCLUDE_TREES; i_opts.start = "c"; i_opts.end = "k/D"; cl_git_pass(git_iterator_for_index(&i, index, &i_opts)); expect_iterator_items(i, 8, NULL, 8, NULL); git_iterator_free(i); i_opts.start = "k"; i_opts.end = "k/Z"; cl_git_pass(git_iterator_for_index(&i, index, &i_opts)); expect_iterator_items(i, 4, NULL, 4, NULL); git_iterator_free(i); /* no auto expand (implies trees included) */ i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND; i_opts.start = "c"; i_opts.end = "k/D"; cl_git_pass(git_iterator_for_index(&i, index, &i_opts)); expect_iterator_items(i, 5, NULL, 8, NULL); git_iterator_free(i); i_opts.start = "k"; i_opts.end = "k/Z"; cl_git_pass(git_iterator_for_index(&i, index, &i_opts)); expect_iterator_items(i, 1, NULL, 4, NULL); git_iterator_free(i); /* force case insensitivity */ cl_git_pass(git_index_set_caps(index, caps | GIT_INDEXCAP_IGNORE_CASE)); /* autoexpand with no tree entries over range */ i_opts.flags = 0; i_opts.start = "c"; i_opts.end = "k/D"; cl_git_pass(git_iterator_for_index(&i, index, &i_opts)); expect_iterator_items(i, 13, NULL, 13, NULL); git_iterator_free(i); i_opts.start = "k"; i_opts.end = "k/Z"; cl_git_pass(git_iterator_for_index(&i, index, &i_opts)); expect_iterator_items(i, 5, NULL, 5, NULL); git_iterator_free(i); /* auto expand with tree entries */ i_opts.flags = GIT_ITERATOR_INCLUDE_TREES; i_opts.start = "c"; i_opts.end = "k/D"; cl_git_pass(git_iterator_for_index(&i, index, &i_opts)); expect_iterator_items(i, 14, NULL, 14, NULL); git_iterator_free(i); i_opts.start = "k"; i_opts.end = "k/Z"; cl_git_pass(git_iterator_for_index(&i, index, &i_opts)); expect_iterator_items(i, 6, NULL, 6, NULL); git_iterator_free(i); /* no auto expand (implies trees included) */ i_opts.flags = GIT_ITERATOR_DONT_AUTOEXPAND; i_opts.start = "c"; i_opts.end = "k/D"; cl_git_pass(git_iterator_for_index(&i, index, &i_opts)); expect_iterator_items(i, 9, NULL, 14, NULL); git_iterator_free(i); i_opts.start = "k"; i_opts.end = "k/Z"; cl_git_pass(git_iterator_for_index(&i, index, &i_opts)); expect_iterator_items(i, 1, NULL, 6, NULL); git_iterator_free(i); cl_git_pass(git_index_set_caps(index, caps)); git_index_free(index); }
void test_status_worktree__with_directory_in_pathlist(void) { git_repository *repo = cl_git_sandbox_init("testrepo2"); git_index *index; git_status_options opts = GIT_STATUS_OPTIONS_INIT; git_status_list *statuslist; const git_status_entry *status; size_t i, entrycount; bool native_ignore_case; char *subdir_path = "subdir"; cl_git_pass(git_repository_index(&index, repo)); native_ignore_case = (git_index_caps(index) & GIT_INDEXCAP_IGNORE_CASE) != 0; git_index_free(index); opts.pathspec.strings = &subdir_path; opts.pathspec.count = 1; opts.flags = GIT_STATUS_OPT_DEFAULTS | GIT_STATUS_OPT_INCLUDE_UNMODIFIED | GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH; opts.show = GIT_STATUS_SHOW_WORKDIR_ONLY; git_status_list_new(&statuslist, repo, &opts); entrycount = git_status_list_entrycount(statuslist); cl_assert_equal_i(4, entrycount); for (i = 0; i < entrycount; i++) { status = git_status_byindex(statuslist, i); cl_assert_equal_i(0, status->status); cl_assert_equal_s(native_ignore_case ? testrepo2_subdir_paths_icase[i] : testrepo2_subdir_paths[i], status->index_to_workdir->old_file.path); } git_status_list_free(statuslist); opts.show = GIT_STATUS_SHOW_INDEX_ONLY; git_status_list_new(&statuslist, repo, &opts); entrycount = git_status_list_entrycount(statuslist); cl_assert_equal_i(4, entrycount); for (i = 0; i < entrycount; i++) { status = git_status_byindex(statuslist, i); cl_assert_equal_i(0, status->status); cl_assert_equal_s(native_ignore_case ? testrepo2_subdir_paths_icase[i] : testrepo2_subdir_paths[i], status->head_to_index->old_file.path); } git_status_list_free(statuslist); opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR; git_status_list_new(&statuslist, repo, &opts); entrycount = git_status_list_entrycount(statuslist); cl_assert_equal_i(4, entrycount); for (i = 0; i < entrycount; i++) { status = git_status_byindex(statuslist, i); cl_assert_equal_i(0, status->status); cl_assert_equal_s(native_ignore_case ? testrepo2_subdir_paths_icase[i] : testrepo2_subdir_paths[i], status->index_to_workdir->old_file.path); } git_status_list_free(statuslist); }
unsigned int Index::getCapabilities()const { return git_index_caps(data()); }