void test_submodule_status__ignore_untracked(void) { unsigned int status; git_submodule *sm; git_buf path = GIT_BUF_INIT; git_submodule_ignore_t ign = GIT_SUBMODULE_IGNORE_UNTRACKED; cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "sm_unchanged")); cl_git_pass(git_futils_rmdir_r(git_buf_cstr(&path), NULL, GIT_RMDIR_REMOVE_FILES)); cl_git_pass(git_submodule_foreach(g_repo, set_sm_ignore, &ign)); cl_git_fail(git_submodule_lookup(&sm, g_repo, "not_submodule")); cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_index")); cl_git_pass(git_submodule_status(&status, sm)); cl_assert((status & GIT_SUBMODULE_STATUS_WD_INDEX_MODIFIED) != 0); cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head")); cl_git_pass(git_submodule_status(&status, sm)); cl_assert((status & GIT_SUBMODULE_STATUS_WD_MODIFIED) != 0); cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_file")); cl_git_pass(git_submodule_status(&status, sm)); cl_assert((status & GIT_SUBMODULE_STATUS_WD_WD_MODIFIED) != 0); cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_untracked_file")); cl_git_pass(git_submodule_status(&status, sm)); cl_assert(GIT_SUBMODULE_STATUS_IS_UNMODIFIED(status)); cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_missing_commits")); cl_git_pass(git_submodule_status(&status, sm)); cl_assert((status & GIT_SUBMODULE_STATUS_WD_MODIFIED) != 0); cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_added_and_uncommited")); cl_git_pass(git_submodule_status(&status, sm)); cl_assert((status & GIT_SUBMODULE_STATUS_INDEX_ADDED) != 0); /* removed sm_unchanged for deleted workdir */ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged")); cl_git_pass(git_submodule_status(&status, sm)); cl_assert((status & GIT_SUBMODULE_STATUS_WD_DELETED) != 0); /* now mkdir sm_unchanged to test uninitialized */ cl_git_pass(git_futils_mkdir(git_buf_cstr(&path), NULL, 0755, 0)); cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged")); cl_git_pass(git_submodule_reload(sm)); cl_git_pass(git_submodule_status(&status, sm)); cl_assert((status & GIT_SUBMODULE_STATUS_WD_UNINITIALIZED) != 0); /* update sm_changed_head in index */ cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head")); cl_git_pass(git_submodule_add_to_index(sm, true)); /* reload is not needed because add_to_index updates the submodule data */ cl_git_pass(git_submodule_status(&status, sm)); cl_assert((status & GIT_SUBMODULE_STATUS_INDEX_MODIFIED) != 0); git_buf_free(&path); }
static void assert_non_exisitng_branch_removal(const char *branch_name, git_branch_t branch_type) { int error; error = git_branch_delete(repo, branch_name, branch_type); cl_git_fail(error); cl_assert_equal_i(GIT_ENOTFOUND, error); }
void test_merge_workdir_dirty__affected_dirty_files_disallowed(void) { char **files; size_t i; for (i = 0, files = affected[i]; files[0]; files = affected[++i]) cl_git_fail(merge_dirty_files(files)); }
void test_refs_revparse__to_type(void) { test_object("wrapped_tag^{commit}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); test_object("wrapped_tag^{tree}", "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162"); test_object("point_to_blob^{blob}", "1385f264afb75a56a5bec74243be9b367ba4ca08"); cl_git_fail(git_revparse_single(&g_obj, g_repo, "wrapped_tag^{blob}")); }
void test_index_crlf__safecrlf_true_no_attrs(void) { cl_repo_set_bool(g_repo, "core.autocrlf", true); cl_repo_set_bool(g_repo, "core.safecrlf", true); cl_git_mkfile("crlf/newfile.txt", ALL_LF_TEXT_RAW); cl_git_pass(git_index_add_bypath(g_index, "newfile.txt")); cl_git_mkfile("crlf/newfile.txt", ALL_CRLF_TEXT_RAW); cl_git_pass(git_index_add_bypath(g_index, "newfile.txt")); cl_git_mkfile("crlf/newfile.txt", MORE_CRLF_TEXT_RAW); cl_git_fail(git_index_add_bypath(g_index, "newfile.txt")); cl_git_mkfile("crlf/newfile.txt", MORE_LF_TEXT_RAW); cl_git_fail(git_index_add_bypath(g_index, "newfile.txt")); }
void test_clone_nonetwork__fail_with_already_existing_but_non_empty_directory(void) { cl_set_cleanup(&cleanup_repository, "./foo"); p_mkdir("./foo", GIT_DIR_MODE); cl_git_mkfile("./foo/bar", "Baz!"); cl_git_fail(git_clone(&g_repo, LIVE_REPO_URL, "./foo", NULL, NULL, NULL)); }
void test_checkout_index__cannot_checkout_a_bare_repository(void) { test_checkout_index__cleanup(); g_repo = cl_git_sandbox_init("testrepo.git"); cl_git_fail(git_checkout_index(g_repo, NULL, NULL)); }
/* * $ git notes --ref fanout list 8496071c1b46c854b31185ea97743be6a8774479 * 08b041783f40edfe12bb406c9c9a8a040177c125 */ void test_notes_notes__creating_a_note_on_a_target_which_already_has_one_returns_EEXISTS(void) { int error; git_oid note_oid, target_oid; cl_git_pass(git_oid_fromstr(&target_oid, "08b041783f40edfe12bb406c9c9a8a040177c125")); create_note(¬e_oid, NULL, "08b041783f40edfe12bb406c9c9a8a040177c125", "hello world\n"); error = git_note_create(¬e_oid, _repo, NULL, _sig, _sig, &target_oid, "hello world\n", 0); cl_git_fail(error); cl_assert_equal_i(GIT_EEXISTS, error); create_note(¬e_oid, "refs/notes/some/namespace", "08b041783f40edfe12bb406c9c9a8a040177c125", "hello world\n"); error = git_note_create(¬e_oid, _repo, "refs/notes/some/namespace", _sig, _sig, &target_oid, "hello world\n", 0); cl_git_fail(error); cl_assert_equal_i(GIT_EEXISTS, error); }
static void test_copy_note( const git_rebase_options *opts, bool should_exist) { git_rebase *rebase; git_reference *branch_ref, *upstream_ref; git_annotated_commit *branch_head, *upstream_head; git_commit *branch_commit; git_rebase_operation *rebase_operation; git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT; git_oid note_id, commit_id; git_note *note = NULL; int error; checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE; cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/gravy")); cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal")); cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref)); cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref)); cl_git_pass(git_reference_peel((git_object **)&branch_commit, branch_ref, GIT_OBJ_COMMIT)); /* Add a note to a commit */ cl_git_pass(git_note_create(¬e_id, repo, "refs/notes/test", git_commit_author(branch_commit), git_commit_committer(branch_commit), git_commit_id(branch_commit), "This is a commit note.", 0)); cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, opts)); cl_git_pass(git_rebase_next(&rebase_operation, rebase, &checkout_opts)); cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature, NULL, NULL)); cl_git_pass(git_rebase_finish(rebase, signature, opts)); cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo)); if (should_exist) { cl_git_pass(git_note_read(¬e, repo, "refs/notes/test", &commit_id)); cl_assert_equal_s("This is a commit note.", git_note_message(note)); } else { cl_git_fail(error = git_note_read(¬e, repo, "refs/notes/test", &commit_id)); cl_assert_equal_i(GIT_ENOTFOUND, error); } git_note_free(note); git_commit_free(branch_commit); git_annotated_commit_free(branch_head); git_annotated_commit_free(upstream_head); git_reference_free(branch_ref); git_reference_free(upstream_ref); git_rebase_free(rebase); }
void test_diff_tree__larger_hunks(void) { const char *a_commit = "d70d245ed97ed2aa596dd1af6536e4bfdb047b69"; const char *b_commit = "7a9e0b02e63179929fed24f0a3e0f19168114d10"; size_t d, num_d, h, num_h, l, num_l; git_patch *patch; const git_diff_hunk *hunk; const git_diff_line *line; g_repo = cl_git_sandbox_init("diff"); cl_assert((a = resolve_commit_oid_to_tree(g_repo, a_commit)) != NULL); cl_assert((b = resolve_commit_oid_to_tree(g_repo, b_commit)) != NULL); opts.context_lines = 1; opts.interhunk_lines = 0; cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts)); num_d = git_diff_num_deltas(diff); for (d = 0; d < num_d; ++d) { cl_git_pass(git_patch_from_diff(&patch, diff, d)); cl_assert(patch); num_h = git_patch_num_hunks(patch); for (h = 0; h < num_h; h++) { cl_git_pass(git_patch_get_hunk(&hunk, &num_l, patch, h)); for (l = 0; l < num_l; ++l) { cl_git_pass(git_patch_get_line_in_hunk(&line, patch, h, l)); cl_assert(line); } cl_git_fail(git_patch_get_line_in_hunk(&line, patch, h, num_l)); } cl_git_fail(git_patch_get_hunk(&hunk, &num_l, patch, num_h)); git_patch_free(patch); } cl_git_fail(git_patch_from_diff(&patch, diff, num_d)); cl_assert_equal_i(2, (int)num_d); }
void test_checkout_index__validates_struct_version(void) { git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT; const git_error *err; opts.version = 1024; cl_git_fail(git_checkout_index(g_repo, NULL, &opts)); err = giterr_last(); cl_assert_equal_i(err->klass, GITERR_INVALID); opts.version = 0; giterr_clear(); cl_git_fail(git_checkout_index(g_repo, NULL, &opts)); err = giterr_last(); cl_assert_equal_i(err->klass, GITERR_INVALID); }
// query the details on a parsed commit void test_commit_parse__details0(void) { static const char *commit_ids[] = { "a4a7dce85cf63874e984719f4fdd239f5145052f", /* 0 */ "9fd738e8f7967c078dceed8190330fc8648ee56a", /* 1 */ "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", /* 2 */ "c47800c7266a2be04c571c04d5a6614691ea99bd", /* 3 */ "8496071c1b46c854b31185ea97743be6a8774479", /* 4 */ "5b5b025afb0b4c913b4c338a42934a3863bf3644", /* 5 */ "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", /* 6 */ }; const size_t commit_count = sizeof(commit_ids) / sizeof(const char *); unsigned int i; for (i = 0; i < commit_count; ++i) { git_oid id; git_commit *commit; const git_signature *author, *committer; const char *message; git_time_t commit_time; unsigned int parents, p; git_commit *parent = NULL, *old_parent = NULL; git_oid_fromstr(&id, commit_ids[i]); cl_git_pass(git_commit_lookup(&commit, g_repo, &id)); message = git_commit_message(commit); author = git_commit_author(commit); committer = git_commit_committer(commit); commit_time = git_commit_time(commit); parents = git_commit_parentcount(commit); cl_assert_equal_s("Scott Chacon", author->name); cl_assert_equal_s("*****@*****.**", author->email); cl_assert_equal_s("Scott Chacon", committer->name); cl_assert_equal_s("*****@*****.**", committer->email); cl_assert(message != NULL); cl_assert(strchr(message, '\n') != NULL); cl_assert(commit_time > 0); cl_assert(parents <= 2); for (p = 0;p < parents;p++) { if (old_parent != NULL) git_commit_free(old_parent); old_parent = parent; cl_git_pass(git_commit_parent(&parent, commit, p)); cl_assert(parent != NULL); cl_assert(git_commit_author(parent) != NULL); // is it really a commit? } git_commit_free(old_parent); git_commit_free(parent); cl_git_fail(git_commit_parent(&parent, commit, parents)); git_commit_free(commit); } }
void test_refs_branches_delete__can_not_delete_a_branch_if_HEAD_is_missing(void) { git_reference *head; cl_git_pass(git_reference_lookup(&head, repo, GIT_HEAD_FILE)); git_reference_delete(head); cl_git_fail(git_branch_delete(repo, "br2", GIT_BRANCH_LOCAL)); }
void test_network_cred__stock_userpass_validates_that_method_is_allowed(void) { git_cred *cred; git_cred_userpass_payload payload = {"user", "pass"}; cl_git_fail(git_cred_userpass(&cred, NULL, NULL, 0, &payload)); cl_git_pass(git_cred_userpass(&cred, NULL, NULL, GIT_CREDTYPE_USERPASS_PLAINTEXT, &payload)); cred->free(cred); }
static void expect_unquote_fail(const char *quoted) { git_buf buf = GIT_BUF_INIT; cl_git_pass(git_buf_puts(&buf, quoted)); cl_git_fail(git_buf_unquote(&buf)); git_buf_dispose(&buf); }
void test_network_remote_rename__cannot_rename_an_inmemory_remote(void) { git_remote *remote; cl_git_pass(git_remote_create_inmemory(&remote, _repo, NULL, "file:///blah")); cl_git_fail(git_remote_rename(remote, "newname", NULL, NULL)); git_remote_free(remote); }
void test_refs_revparse__reflog(void) { cl_git_fail(git_revparse_single(&g_obj, g_repo, "@{-xyz}")); cl_git_fail(git_revparse_single(&g_obj, g_repo, "@{-0}")); cl_git_fail(git_revparse_single(&g_obj, g_repo, "@{1000}")); cl_assert_equal_i(GIT_ENOTFOUND, git_revparse_single(&g_obj, g_repo, "nope@{0}")); cl_assert_equal_i(GIT_ENOTFOUND, git_revparse_single(&g_obj, g_repo, "master@{31415}")); test_object("@{-2}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); test_object("@{-1}", "a4a7dce85cf63874e984719f4fdd239f5145052f"); test_object("master@{0}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); test_object("master@{1}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); test_object("@{0}", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); test_object("@{1}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); test_object("master@{upstream}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); test_object("master@{u}", "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); }
void test_win32_longpath__errmsg_on_checkout(void) { #ifdef GIT_WIN32 git_repository *repo; cl_git_fail(git_clone(&repo, cl_fixture("testrepo.git"), path.ptr, NULL)); assert_name_too_long(); #endif }
void test_online_clone__ssh_cannot_change_username(void) { #ifndef GIT_SSH clar__skip(); #endif g_options.fetch_opts.callbacks.credentials = cred_foo_bar; cl_git_fail(git_clone(&g_repo, "ssh://[email protected]/libgit2/TestGitRepository", "./foo", &g_options)); }
void test_refs_normalize__buffer_has_to_be_big_enough_to_hold_the_normalized_version(void) { char buffer_out[21]; cl_git_pass(git_reference_normalize_name( buffer_out, 21, "refs//heads///long///name", GIT_REF_FORMAT_NORMAL)); cl_git_fail(git_reference_normalize_name( buffer_out, 20, "refs//heads///long///name", GIT_REF_FORMAT_NORMAL)); }
void test_checkout_tree__conflict_on_ignored_folder_when_not_overwriting(void) { int error; cl_git_fail(error = checkout_tree_with_blob_ignored_in_workdir( GIT_CHECKOUT_SAFE | GIT_CHECKOUT_DONT_OVERWRITE_IGNORED, true)); cl_assert_equal_i(GIT_ECONFLICT, error); }
void test_refs_branches_move__can_not_move_a_non_branch(void) { git_reference *tag, *new_ref; cl_git_pass(git_reference_lookup(&tag, repo, "refs/tags/e90810b")); cl_git_fail(git_branch_move(&new_ref, tag, NEW_BRANCH_NAME, 0)); git_reference_free(tag); }
void test_refs_read__nonexisting_tag(void) { // lookup a loose tag reference that doesn't exist git_reference *reference; cl_git_fail(git_reference_lookup(&reference, g_repo, non_existing_tag_ref_name)); git_reference_free(reference); }
void test_revwalk_basic__disallow_non_commit(void) { git_oid oid; revwalk_basic_setup_walk(NULL); cl_git_pass(git_oid_fromstr(&oid, "521d87c1ec3aef9824daf6d96cc0ae3710766d91")); cl_git_fail(git_revwalk_push(_walk, &oid)); }
void test_rebase_merge__finish(void) { git_rebase *rebase; git_reference *branch_ref, *upstream_ref, *head_ref; git_annotated_commit *branch_head, *upstream_head; git_rebase_operation *rebase_operation; git_oid commit_id; git_reflog *reflog; const git_reflog_entry *reflog_entry; int error; cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/gravy")); cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal")); cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref)); cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref)); cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL)); cl_git_pass(git_rebase_next(&rebase_operation, rebase)); cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature, NULL, NULL)); cl_git_fail(error = git_rebase_next(&rebase_operation, rebase)); cl_assert_equal_i(GIT_ITEROVER, error); cl_git_pass(git_rebase_finish(rebase, signature)); cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo)); cl_git_pass(git_reference_lookup(&head_ref, repo, "HEAD")); cl_assert_equal_i(GIT_REF_SYMBOLIC, git_reference_type(head_ref)); cl_assert_equal_s("refs/heads/gravy", git_reference_symbolic_target(head_ref)); /* Make sure the reflogs are updated appropriately */ cl_git_pass(git_reflog_read(&reflog, repo, "HEAD")); cl_assert(reflog_entry = git_reflog_entry_byindex(reflog, 0)); cl_assert_equal_oid(&commit_id, git_reflog_entry_id_old(reflog_entry)); cl_assert_equal_oid(&commit_id, git_reflog_entry_id_new(reflog_entry)); cl_assert_equal_s("rebase finished: returning to refs/heads/gravy", git_reflog_entry_message(reflog_entry)); git_reflog_free(reflog); cl_git_pass(git_reflog_read(&reflog, repo, "refs/heads/gravy")); cl_assert(reflog_entry = git_reflog_entry_byindex(reflog, 0)); cl_assert_equal_oid(git_annotated_commit_id(branch_head), git_reflog_entry_id_old(reflog_entry)); cl_assert_equal_oid(&commit_id, git_reflog_entry_id_new(reflog_entry)); cl_assert_equal_s("rebase finished: refs/heads/gravy onto f87d14a4a236582a0278a916340a793714256864", git_reflog_entry_message(reflog_entry)); git_reflog_free(reflog); git_annotated_commit_free(branch_head); git_annotated_commit_free(upstream_head); git_reference_free(head_ref); git_reference_free(branch_ref); git_reference_free(upstream_ref); git_rebase_free(rebase); }
/* this test is equivalent to t18-status.c:singlestatus4 */ void test_status_worktree__single_folder(void) { int error; unsigned int status_flags; git_repository *repo = cl_git_sandbox_init("status"); error = git_status_file(&status_flags, repo, "subdir"); cl_git_fail(error); cl_assert(error != GIT_ENOTFOUND); }
/* this test is equivalent to t18-status.c:singlestatus2 */ void test_status_worktree__single_nonexistent_file_empty_repo(void) { int error; unsigned int status_flags; git_repository *repo = cl_git_sandbox_init("empty_standard_repo"); error = git_status_file(&status_flags, repo, "nonexistent"); cl_git_fail(error); cl_assert(error == GIT_ENOTFOUND); }
void test_repo_head__set_head_detached_Fails_when_the_object_isnt_a_commitish(void) { git_object *blob; cl_git_pass(git_revparse_single(&blob, repo, "point_to_blob")); cl_git_fail(git_repository_set_head_detached(repo, git_object_id(blob))); git_object_free(blob); }
void test_repo_head__detach_head_Fails_if_HEAD_and_point_to_a_non_commitish(void) { git_reference *head; cl_git_pass(git_reference_symbolic_create(&head, repo, GIT_HEAD_FILE, "refs/tags/point_to_blob", 1, NULL)); cl_git_fail(git_repository_detach_head(repo)); git_reference_free(head); }
void test_notes_notes__can_remove_a_note_in_an_existing_fanout(void) { git_oid target_oid; git_note *note; cl_git_pass(git_oid_fromstr(&target_oid, "8496071c1b46c854b31185ea97743be6a8774479")); cl_git_pass(git_note_remove(_repo, "refs/notes/fanout", _sig, _sig, &target_oid)); cl_git_fail(git_note_read(¬e, _repo, "refs/notes/fanout", &target_oid)); }