/* Ensure that files do not match folder cases */ void test_attr_ignore__dont_ignore_files_for_folder(void) { cl_git_rmfile("attr/.gitignore"); cl_git_mkfile("attr/dir/.gitignore", "test/\n"); /* Create "test" as a file; ensure it is not ignored. */ cl_git_mkfile("attr/dir/test", "This is a file."); assert_is_ignored(false, "dir/test"); if (cl_repo_get_bool(g_repo, "core.ignorecase")) assert_is_ignored(false, "dir/TeSt"); /* Create "test" as a directory; ensure it is ignored. */ cl_git_rmfile("attr/dir/test"); cl_must_pass(p_mkdir("attr/dir/test", 0777)); assert_is_ignored(true, "dir/test"); if (cl_repo_get_bool(g_repo, "core.ignorecase")) assert_is_ignored(true, "dir/TeSt"); /* Remove "test" entirely; ensure it is not ignored. * (As it doesn't exist, it is not a directory.) */ cl_must_pass(p_rmdir("attr/dir/test")); assert_is_ignored(false, "dir/test"); if (cl_repo_get_bool(g_repo, "core.ignorecase")) assert_is_ignored(false, "dir/TeSt"); }
void test_repo_init__extended_with_template_and_shared_mode(void) { git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; int filemode = true; const char *repo_path = NULL; cl_set_cleanup(&cleanup_repository, "init_shared_from_tpl"); template_sandbox("template"); opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE; opts.template_path = "template"; opts.mode = GIT_REPOSITORY_INIT_SHARED_GROUP; cl_git_pass(git_repository_init_ext(&_repo, "init_shared_from_tpl", &opts)); cl_assert(!git_repository_is_bare(_repo)); cl_assert(!git__suffixcmp(git_repository_path(_repo), "/init_shared_from_tpl/.git/")); filemode = cl_repo_get_bool(_repo, "core.filemode"); repo_path = git_repository_path(_repo); assert_mode_seems_okay(repo_path, "hooks", GIT_FILEMODE_TREE | GIT_REPOSITORY_INIT_SHARED_GROUP, true, filemode); assert_mode_seems_okay(repo_path, "info", GIT_FILEMODE_TREE | GIT_REPOSITORY_INIT_SHARED_GROUP, true, filemode); assert_mode_seems_okay(repo_path, "description", GIT_FILEMODE_BLOB, false, filemode); validate_templates(_repo, "template"); cl_fixture_cleanup("template"); }
/* Ensure that the .gitignore in the subdirectory only affects * items in the subdirectory. */ void test_attr_ignore__gitignore_in_subdir(void) { cl_git_rmfile("attr/.gitignore"); cl_must_pass(p_mkdir("attr/dir1", 0777)); cl_must_pass(p_mkdir("attr/dir1/dir2", 0777)); cl_must_pass(p_mkdir("attr/dir1/dir2/dir3", 0777)); cl_git_mkfile("attr/dir1/dir2/dir3/.gitignore", "dir1/\ndir1/subdir/"); assert_is_ignored(false, "dir1/file"); assert_is_ignored(false, "dir1/dir2/file"); assert_is_ignored(false, "dir1/dir2/dir3/file"); assert_is_ignored(true, "dir1/dir2/dir3/dir1/file"); assert_is_ignored(true, "dir1/dir2/dir3/dir1/subdir/foo"); if (cl_repo_get_bool(g_repo, "core.ignorecase")) { cl_git_mkfile("attr/dir1/dir2/dir3/.gitignore", "DiR1/\nDiR1/subdir/\n"); assert_is_ignored(false, "dir1/file"); assert_is_ignored(false, "dir1/dir2/file"); assert_is_ignored(false, "dir1/dir2/dir3/file"); assert_is_ignored(true, "dir1/dir2/dir3/dir1/file"); assert_is_ignored(true, "dir1/dir2/dir3/dir1/subdir/foo"); } }
void test_repo_init__extended_with_template_and_shared_mode(void) { git_buf expected = GIT_BUF_INIT; git_buf actual = GIT_BUF_INIT; git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; int filemode = true; const char *repo_path = NULL; cl_set_cleanup(&cleanup_repository, "init_shared_from_tpl"); template_sandbox("template"); opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE; opts.template_path = "template"; opts.mode = GIT_REPOSITORY_INIT_SHARED_GROUP; cl_git_pass(git_repository_init_ext(&_repo, "init_shared_from_tpl", &opts)); cl_assert(!git_repository_is_bare(_repo)); cl_assert(!git__suffixcmp(git_repository_path(_repo), "/init_shared_from_tpl/.git/")); filemode = cl_repo_get_bool(_repo, "core.filemode"); cl_git_pass(git_futils_readbuffer( &expected, "template/description")); cl_git_pass(git_futils_readbuffer( &actual, "init_shared_from_tpl/.git/description")); cl_assert_equal_s(expected.ptr, actual.ptr); git_buf_free(&expected); git_buf_free(&actual); repo_path = git_repository_path(_repo); assert_mode_seems_okay(repo_path, "hooks", GIT_FILEMODE_TREE | GIT_REPOSITORY_INIT_SHARED_GROUP, true, filemode); assert_mode_seems_okay(repo_path, "info", GIT_FILEMODE_TREE | GIT_REPOSITORY_INIT_SHARED_GROUP, true, filemode); assert_mode_seems_okay(repo_path, "description", GIT_FILEMODE_BLOB, false, filemode); /* for a non-symlinked hook, it should have shared permissions now */ assert_hooks_match( "template", git_repository_path(_repo), "hooks/update.sample", filemode); /* for a symlinked hook, the permissions still should match the * source link, not the GIT_REPOSITORY_INIT_SHARED_GROUP value */ assert_hooks_match( "template", git_repository_path(_repo), "hooks/link.sample", filemode); cl_fixture_cleanup("template"); }
void test_refs_branches_move__can_move_with_unicode(void) { git_reference *original_ref, *new_ref; const char *new_branch_name = "\x41\xCC\x8A\x73\x74\x72\x6F\xCC\x88\x6D"; cl_git_pass(git_reference_lookup(&original_ref, repo, "refs/heads/br2")); cl_git_pass(git_branch_move(&new_ref, original_ref, new_branch_name, 0)); if (cl_repo_get_bool(repo, "core.precomposeunicode")) cl_assert_equal_s(GIT_REFS_HEADS_DIR "\xC3\x85\x73\x74\x72\xC3\xB6\x6D", git_reference_name(new_ref)); else cl_assert_equal_s(GIT_REFS_HEADS_DIR "\x41\xCC\x8A\x73\x74\x72\x6F\xCC\x88\x6D", git_reference_name(new_ref)); git_reference_free(original_ref); git_reference_free(new_ref); }
void test_repo_init__extended_with_template(void) { git_buf expected = GIT_BUF_INIT; git_buf actual = GIT_BUF_INIT; git_repository_init_options opts = GIT_REPOSITORY_INIT_OPTIONS_INIT; int filemode; cl_set_cleanup(&cleanup_repository, "templated.git"); template_sandbox("template"); opts.flags = GIT_REPOSITORY_INIT_MKPATH | GIT_REPOSITORY_INIT_BARE | GIT_REPOSITORY_INIT_EXTERNAL_TEMPLATE; opts.template_path = "template"; cl_git_pass(git_repository_init_ext(&_repo, "templated.git", &opts)); cl_assert(git_repository_is_bare(_repo)); cl_assert(!git__suffixcmp(git_repository_path(_repo), "/templated.git/")); cl_git_pass(git_futils_readbuffer(&expected, "template/description")); cl_git_pass(git_futils_readbuffer( &actual, "templated.git/description")); cl_assert_equal_s(expected.ptr, actual.ptr); git_buf_free(&expected); git_buf_free(&actual); filemode = cl_repo_get_bool(_repo, "core.filemode"); assert_hooks_match( "template", git_repository_path(_repo), "hooks/update.sample", filemode); assert_hooks_match( "template", git_repository_path(_repo), "hooks/link.sample", filemode); cl_fixture_cleanup("template"); }
void test_repo_init__reinit_overwrites_filemode(void) { int expected = cl_is_chmod_supported(), current_value; /* Init a new repo */ cl_set_cleanup(&cleanup_repository, "overwrite.git"); cl_git_pass(git_repository_init(&_repo, "overwrite.git", 1)); /* Change the "core.filemode" config value to something unlikely */ cl_repo_set_bool(_repo, "core.filemode", !expected); git_repository_free(_repo); _repo = NULL; /* Reinit the repository */ cl_git_pass(git_repository_init(&_repo, "overwrite.git", 1)); /* Ensure the "core.filemode" config value has been reset */ current_value = cl_repo_get_bool(_repo, "core.filemode"); cl_assert_equal_i(expected, current_value); }
void test_refs_branches_create__can_create_branch_with_unicode(void) { const char *nfc = "\xC3\x85\x73\x74\x72\xC3\xB6\x6D"; const char *nfd = "\x41\xCC\x8A\x73\x74\x72\x6F\xCC\x88\x6D"; const char *emoji = "\xF0\x9F\x8D\xB7"; const char *names[] = { nfc, nfd, emoji }; const char *alt[] = { nfd, nfc, NULL }; const char *expected[] = { nfc, nfd, emoji }; unsigned int i; bool fs_decompose_unicode = git_path_does_fs_decompose_unicode(git_repository_path(repo)); retrieve_known_commit(&target, repo); if (cl_repo_get_bool(repo, "core.precomposeunicode")) expected[1] = nfc; /* test decomp. because not all Mac filesystems decompose unicode */ else if (fs_decompose_unicode) expected[0] = nfd; for (i = 0; i < ARRAY_SIZE(names); ++i) { const char *name; cl_git_pass(git_branch_create( &branch, repo, names[i], target, 0, NULL, NULL)); cl_git_pass(git_oid_cmp( git_reference_target(branch), git_commit_id(target))); cl_git_pass(git_branch_name(&name, branch)); cl_assert_equal_s(expected[i], name); assert_branch_matches_name(expected[i], names[i]); if (fs_decompose_unicode && alt[i]) assert_branch_matches_name(expected[i], alt[i]); cl_git_pass(git_branch_delete(branch)); git_reference_free(branch); branch = NULL; } }
static void validate_templates(git_repository *repo, const char *template_path) { git_buf template_description = GIT_BUF_INIT; git_buf repo_description = GIT_BUF_INIT; git_buf expected = GIT_BUF_INIT; git_buf actual = GIT_BUF_INIT; int filemode; cl_git_pass(git_buf_joinpath(&template_description, template_path, "description")); cl_git_pass(git_buf_joinpath(&repo_description, git_repository_path(repo), "description")); cl_git_pass(git_futils_readbuffer(&expected, template_description.ptr)); cl_git_pass(git_futils_readbuffer(&actual, repo_description.ptr)); cl_assert_equal_s(expected.ptr, actual.ptr); filemode = cl_repo_get_bool(repo, "core.filemode"); assert_hooks_match( template_path, git_repository_path(repo), "hooks/update.sample", filemode); assert_hooks_match( template_path, git_repository_path(repo), "hooks/link.sample", filemode); assert_hooks_match( template_path, git_repository_path(repo), "hooks/.dotfile", filemode); git_buf_free(&expected); git_buf_free(&actual); git_buf_free(&repo_description); git_buf_free(&template_description); }
void test_index_conflicts__case_matters(void) { const git_index_entry *conflict_entry[3]; git_oid oid; const char *upper_case = "DIFFERS-IN-CASE.TXT"; const char *mixed_case = "Differs-In-Case.txt"; const char *correct_case; bool ignorecase = cl_repo_get_bool(repo, "core.ignorecase"); git_index_entry ancestor_entry, our_entry, their_entry; memset(&ancestor_entry, 0x0, sizeof(git_index_entry)); memset(&our_entry, 0x0, sizeof(git_index_entry)); memset(&their_entry, 0x0, sizeof(git_index_entry)); ancestor_entry.path = upper_case; GIT_IDXENTRY_STAGE_SET(&ancestor_entry, GIT_INDEX_STAGE_ANCESTOR); git_oid_fromstr(&ancestor_entry.id, CONFLICTS_ONE_ANCESTOR_OID); ancestor_entry.mode = GIT_FILEMODE_BLOB; our_entry.path = upper_case; GIT_IDXENTRY_STAGE_SET(&our_entry, GIT_INDEX_STAGE_OURS); git_oid_fromstr(&our_entry.id, CONFLICTS_ONE_OUR_OID); our_entry.mode = GIT_FILEMODE_BLOB; their_entry.path = upper_case; GIT_IDXENTRY_STAGE_SET(&their_entry, GIT_INDEX_STAGE_THEIRS); git_oid_fromstr(&their_entry.id, CONFLICTS_ONE_THEIR_OID); their_entry.mode = GIT_FILEMODE_BLOB; cl_git_pass(git_index_conflict_add(repo_index, &ancestor_entry, &our_entry, &their_entry)); ancestor_entry.path = mixed_case; GIT_IDXENTRY_STAGE_SET(&ancestor_entry, GIT_INDEX_STAGE_ANCESTOR); git_oid_fromstr(&ancestor_entry.id, CONFLICTS_TWO_ANCESTOR_OID); ancestor_entry.mode = GIT_FILEMODE_BLOB; our_entry.path = mixed_case; GIT_IDXENTRY_STAGE_SET(&ancestor_entry, GIT_INDEX_STAGE_ANCESTOR); git_oid_fromstr(&our_entry.id, CONFLICTS_TWO_OUR_OID); ancestor_entry.mode = GIT_FILEMODE_BLOB; their_entry.path = mixed_case; GIT_IDXENTRY_STAGE_SET(&their_entry, GIT_INDEX_STAGE_THEIRS); git_oid_fromstr(&their_entry.id, CONFLICTS_TWO_THEIR_OID); their_entry.mode = GIT_FILEMODE_BLOB; cl_git_pass(git_index_conflict_add(repo_index, &ancestor_entry, &our_entry, &their_entry)); cl_git_pass(git_index_conflict_get(&conflict_entry[0], &conflict_entry[1], &conflict_entry[2], repo_index, upper_case)); /* * We inserted with mixed case last, so on a case-insensitive * fs we should get the mixed case. */ if (ignorecase) correct_case = mixed_case; else correct_case = upper_case; cl_assert_equal_s(correct_case, conflict_entry[0]->path); git_oid_fromstr(&oid, ignorecase ? CONFLICTS_TWO_ANCESTOR_OID : CONFLICTS_ONE_ANCESTOR_OID); cl_assert_equal_oid(&oid, &conflict_entry[0]->id); cl_assert_equal_s(correct_case, conflict_entry[1]->path); git_oid_fromstr(&oid, ignorecase ? CONFLICTS_TWO_OUR_OID : CONFLICTS_ONE_OUR_OID); cl_assert_equal_oid(&oid, &conflict_entry[1]->id); cl_assert_equal_s(correct_case, conflict_entry[2]->path); git_oid_fromstr(&oid, ignorecase ? CONFLICTS_TWO_THEIR_OID : CONFLICTS_ONE_THEIR_OID); cl_assert_equal_oid(&oid, &conflict_entry[2]->id); cl_git_pass(git_index_conflict_get(&conflict_entry[0], &conflict_entry[1], &conflict_entry[2], repo_index, mixed_case)); cl_assert_equal_s(mixed_case, conflict_entry[0]->path); git_oid_fromstr(&oid, CONFLICTS_TWO_ANCESTOR_OID); cl_assert_equal_oid(&oid, &conflict_entry[0]->id); cl_assert_equal_s(mixed_case, conflict_entry[1]->path); git_oid_fromstr(&oid, CONFLICTS_TWO_OUR_OID); cl_assert_equal_oid(&oid, &conflict_entry[1]->id); cl_assert_equal_s(mixed_case, conflict_entry[2]->path); git_oid_fromstr(&oid, CONFLICTS_TWO_THEIR_OID); cl_assert_equal_oid(&oid, &conflict_entry[2]->id); }
void test_index_addall__repo_lifecycle(void) { int error; git_index *index; git_strarray paths = { NULL, 0 }; char *strs[1]; addall_create_test_repo(true); cl_git_pass(git_repository_index(&index, g_repo)); strs[0] = "file.*"; paths.strings = strs; paths.count = 1; cl_git_pass(git_index_add_all(index, &paths, 0, NULL, NULL)); check_stat_data(index, TEST_DIR "/file.bar", true); check_status(g_repo, 1, 0, 0, 1, 0, 0, 1, 0); cl_git_rewritefile(TEST_DIR "/file.bar", "new content for file"); check_stat_data(index, TEST_DIR "/file.bar", false); check_status(g_repo, 1, 0, 0, 1, 0, 1, 1, 0); cl_git_mkfile(TEST_DIR "/file.zzz", "yet another one"); cl_git_mkfile(TEST_DIR "/other.zzz", "yet another one"); cl_git_mkfile(TEST_DIR "/more.zzz", "yet another one"); check_status(g_repo, 1, 0, 0, 4, 0, 1, 1, 0); cl_git_pass(git_index_update_all(index, NULL, NULL, NULL)); check_stat_data(index, TEST_DIR "/file.bar", true); check_status(g_repo, 1, 0, 0, 4, 0, 0, 1, 0); cl_git_pass(git_index_add_all(index, &paths, 0, NULL, NULL)); check_stat_data(index, TEST_DIR "/file.zzz", true); check_status(g_repo, 2, 0, 0, 3, 0, 0, 1, 0); cl_repo_commit_from_index(NULL, g_repo, NULL, 0, "first commit"); check_status(g_repo, 0, 0, 0, 3, 0, 0, 1, 0); if (cl_repo_get_bool(g_repo, "core.filemode")) { cl_git_pass(git_index_update_all(index, NULL, NULL, NULL)); cl_must_pass(p_chmod(TEST_DIR "/file.zzz", 0777)); cl_git_pass(git_index_update_all(index, NULL, NULL, NULL)); check_status(g_repo, 0, 0, 1, 3, 0, 0, 1, 0); /* go back to what we had before */ cl_must_pass(p_chmod(TEST_DIR "/file.zzz", 0666)); cl_git_pass(git_index_update_all(index, NULL, NULL, NULL)); check_status(g_repo, 0, 0, 0, 3, 0, 0, 1, 0); } /* attempt to add an ignored file - does nothing */ strs[0] = "file.foo"; cl_git_pass(git_index_add_all(index, &paths, 0, NULL, NULL)); check_status(g_repo, 0, 0, 0, 3, 0, 0, 1, 0); /* add with check - should generate error */ error = git_index_add_all( index, &paths, GIT_INDEX_ADD_CHECK_PATHSPEC, NULL, NULL); cl_assert_equal_i(GIT_EINVALIDSPEC, error); check_status(g_repo, 0, 0, 0, 3, 0, 0, 1, 0); /* add with force - should allow */ cl_git_pass(git_index_add_all( index, &paths, GIT_INDEX_ADD_FORCE, NULL, NULL)); check_stat_data(index, TEST_DIR "/file.foo", true); check_status(g_repo, 1, 0, 0, 3, 0, 0, 0, 0); /* now it's in the index, so regular add should work */ cl_git_rewritefile(TEST_DIR "/file.foo", "new content for file"); check_stat_data(index, TEST_DIR "/file.foo", false); check_status(g_repo, 1, 0, 0, 3, 0, 1, 0, 0); cl_git_pass(git_index_add_all(index, &paths, 0, NULL, NULL)); check_stat_data(index, TEST_DIR "/file.foo", true); check_status(g_repo, 1, 0, 0, 3, 0, 0, 0, 0); cl_git_pass(git_index_add_bypath(index, "more.zzz")); check_stat_data(index, TEST_DIR "/more.zzz", true); check_status(g_repo, 2, 0, 0, 2, 0, 0, 0, 0); cl_git_rewritefile(TEST_DIR "/file.zzz", "new content for file"); check_status(g_repo, 2, 0, 0, 2, 0, 1, 0, 0); cl_git_pass(git_index_add_bypath(index, "file.zzz")); check_stat_data(index, TEST_DIR "/file.zzz", true); check_status(g_repo, 2, 0, 1, 2, 0, 0, 0, 0); strs[0] = "*.zzz"; cl_git_pass(git_index_remove_all(index, &paths, NULL, NULL)); check_status(g_repo, 1, 1, 0, 4, 0, 0, 0, 0); cl_git_pass(git_index_add_bypath(index, "file.zzz")); check_status(g_repo, 1, 0, 1, 3, 0, 0, 0, 0); cl_repo_commit_from_index(NULL, g_repo, NULL, 0, "second commit"); check_status(g_repo, 0, 0, 0, 3, 0, 0, 0, 0); cl_must_pass(p_unlink(TEST_DIR "/file.zzz")); check_status(g_repo, 0, 0, 0, 3, 1, 0, 0, 0); /* update_all should be able to remove entries */ cl_git_pass(git_index_update_all(index, NULL, NULL, NULL)); check_status(g_repo, 0, 1, 0, 3, 0, 0, 0, 0); strs[0] = "*"; cl_git_pass(git_index_add_all(index, &paths, 0, NULL, NULL)); check_status(g_repo, 3, 1, 0, 0, 0, 0, 0, 0); /* must be able to remove at any position while still updating other files */ cl_must_pass(p_unlink(TEST_DIR "/.gitignore")); cl_git_rewritefile(TEST_DIR "/file.zzz", "reconstructed file"); cl_git_rewritefile(TEST_DIR "/more.zzz", "altered file reality"); check_status(g_repo, 3, 1, 0, 1, 1, 1, 0, 0); cl_git_pass(git_index_update_all(index, NULL, NULL, NULL)); check_status(g_repo, 2, 1, 0, 1, 0, 0, 0, 0); /* this behavior actually matches 'git add -u' where "file.zzz" has * been removed from the index, so when you go to update, even though * it exists in the HEAD, it is not re-added to the index, leaving it * as a DELETE when comparing HEAD to index and as an ADD comparing * index to worktree */ git_index_free(index); }