void test_checkout_index__can_update_prefixed_files(void) { git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT; cl_assert_equal_i(false, git_path_isfile("./testrepo/README")); cl_assert_equal_i(false, git_path_isfile("./testrepo/branch_file.txt")); cl_assert_equal_i(false, git_path_isfile("./testrepo/new.txt")); cl_git_mkfile("./testrepo/READ", "content\n"); cl_git_mkfile("./testrepo/README.after", "content\n"); cl_git_pass(p_mkdir("./testrepo/branch_file", 0777)); cl_git_pass(p_mkdir("./testrepo/branch_file/contained_dir", 0777)); cl_git_mkfile("./testrepo/branch_file/contained_file", "content\n"); cl_git_pass(p_mkdir("./testrepo/branch_file.txt.after", 0777)); opts.checkout_strategy = GIT_CHECKOUT_SAFE_CREATE | GIT_CHECKOUT_REMOVE_UNTRACKED; cl_git_pass(git_checkout_index(g_repo, NULL, &opts)); /* remove untracked will remove the .gitattributes file before the blobs * were created, so they will have had crlf filtering applied on Windows */ check_file_contents_nocr("./testrepo/README", "hey there\n"); check_file_contents_nocr("./testrepo/branch_file.txt", "hi\nbye!\n"); check_file_contents_nocr("./testrepo/new.txt", "my new file\n"); cl_assert(!git_path_exists("testrepo/READ")); cl_assert(!git_path_exists("testrepo/README.after")); cl_assert(!git_path_exists("testrepo/branch_file")); cl_assert(!git_path_exists("testrepo/branch_file.txt.after")); }
void test_checkout_index__target_directory_from_bare(void) { git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; git_index *index; git_object *head = NULL; checkout_counts cts; memset(&cts, 0, sizeof(cts)); test_checkout_index__cleanup(); g_repo = cl_git_sandbox_init("testrepo.git"); cl_assert(git_repository_is_bare(g_repo)); cl_git_pass(git_repository_index(&index, g_repo)); cl_git_pass(git_revparse_single(&head, g_repo, "HEAD^{tree}")); cl_git_pass(git_index_read_tree(index, (const git_tree *)head)); cl_git_pass(git_index_write(index)); git_index_free(index); opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_RECREATE_MISSING; opts.notify_flags = GIT_CHECKOUT_NOTIFY_ALL; opts.notify_cb = checkout_count_callback; opts.notify_payload = &cts; /* fail to checkout a bare repo */ cl_git_fail(git_checkout_index(g_repo, NULL, &opts)); opts.target_directory = "alternative"; cl_assert(!git_path_isdir("alternative")); cl_git_pass(git_checkout_index(g_repo, NULL, &opts)); cl_assert_equal_i(0, cts.n_untracked); cl_assert_equal_i(0, cts.n_ignored); cl_assert_equal_i(3, cts.n_updates); /* files will have been filtered if needed, so strip CR */ check_file_contents_nocr("./alternative/README", "hey there\n"); check_file_contents_nocr("./alternative/branch_file.txt", "hi\nbye!\n"); check_file_contents_nocr("./alternative/new.txt", "my new file\n"); cl_git_pass(git_futils_rmdir_r( "alternative", NULL, GIT_RMDIR_REMOVE_FILES)); git_object_free(head); }
void test_checkout_tree__target_directory_from_bare(void) { git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; git_oid oid; checkout_counts cts; memset(&cts, 0, sizeof(cts)); test_checkout_tree__cleanup(); /* cleanup default checkout */ g_repo = cl_git_sandbox_init("testrepo.git"); cl_assert(git_repository_is_bare(g_repo)); opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_RECREATE_MISSING; opts.notify_flags = GIT_CHECKOUT_NOTIFY_ALL; opts.notify_cb = checkout_count_callback; opts.notify_payload = &cts; cl_git_pass(git_reference_name_to_id(&oid, g_repo, "HEAD")); cl_git_pass(git_object_lookup(&g_object, g_repo, &oid, GIT_OBJ_ANY)); cl_git_fail(git_checkout_tree(g_repo, g_object, &opts)); opts.target_directory = "alternative"; cl_assert(!git_path_isdir("alternative")); cl_git_pass(git_checkout_tree(g_repo, g_object, &opts)); cl_assert_equal_i(0, cts.n_untracked); cl_assert_equal_i(0, cts.n_ignored); cl_assert_equal_i(3, cts.n_updates); check_file_contents_nocr("./alternative/README", "hey there\n"); check_file_contents_nocr("./alternative/branch_file.txt", "hi\nbye!\n"); check_file_contents_nocr("./alternative/new.txt", "my new file\n"); cl_git_pass(git_futils_rmdir_r( "alternative", NULL, GIT_RMDIR_REMOVE_FILES)); }
void test_checkout_tree__can_update_only(void) { git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; git_oid oid; git_object *obj = NULL; /* first let's get things into a known state - by checkout out the HEAD */ assert_on_branch(g_repo, "master"); opts.checkout_strategy = GIT_CHECKOUT_FORCE; cl_git_pass(git_checkout_head(g_repo, &opts)); cl_assert(!git_path_isdir("testrepo/a")); check_file_contents_nocr("testrepo/branch_file.txt", "hi\nbye!\n"); /* now checkout branch but with update only */ opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_UPDATE_ONLY; cl_git_pass(git_reference_name_to_id(&oid, g_repo, "refs/heads/dir")); cl_git_pass(git_object_lookup(&obj, g_repo, &oid, GIT_OBJ_ANY)); cl_git_pass(git_checkout_tree(g_repo, obj, &opts)); cl_git_pass(git_repository_set_head(g_repo, "refs/heads/dir")); assert_on_branch(g_repo, "dir"); /* this normally would have been created (which was tested separately in * the test_checkout_tree__can_switch_branches test), but with * UPDATE_ONLY it will not have been created. */ cl_assert(!git_path_isdir("testrepo/a")); /* but this file still should have been updated */ check_file_contents_nocr("testrepo/branch_file.txt", "hi\n"); git_object_free(obj); }