void test_refs_branches_delete__can_delete_a_branch_pointed_at_by_detached_HEAD(void) { git_reference *head, *branch; cl_git_pass(git_reference_lookup(&head, repo, GIT_HEAD_FILE)); cl_assert_equal_i(GIT_REF_SYMBOLIC, git_reference_type(head)); cl_assert_equal_s("refs/heads/master", git_reference_symbolic_target(head)); git_reference_free(head); /* Detach HEAD and make it target the commit that "master" points to */ git_repository_detach_head(repo); cl_git_pass(git_branch_lookup(&branch, repo, "master", GIT_BRANCH_LOCAL)); cl_git_pass(git_branch_delete(branch)); git_reference_free(branch); }
void test_status_worktree__update_index_with_symlink_doesnt_change_mode(void) { git_repository *repo = cl_git_sandbox_init("testrepo"); git_reference *head; git_object *head_object; git_index *index; const git_index_entry *idx_entry; git_status_options opts = GIT_STATUS_OPTIONS_INIT; status_entry_counts counts = {0}; const char *expected_paths[] = { "README" }; const unsigned int expected_statuses[] = {GIT_STATUS_WT_NEW}; opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR; opts.flags = GIT_STATUS_OPT_DEFAULTS | GIT_STATUS_OPT_UPDATE_INDEX; cl_git_pass(git_repository_head(&head, repo)); cl_git_pass(git_reference_peel(&head_object, head, GIT_OBJ_COMMIT)); cl_git_pass(git_reset(repo, head_object, GIT_RESET_HARD, NULL)); cl_git_rewritefile("testrepo/README", "This was rewritten."); /* this status rewrites the index because we have changed the * contents of a tracked file */ counts.expected_entry_count = 1; counts.expected_paths = expected_paths; counts.expected_statuses = expected_statuses; cl_git_pass( git_status_foreach_ext(repo, &opts, cb_status__normal, &counts)); cl_assert_equal_i(1, counts.entry_count); /* now ensure that the status's rewrite of the index did not screw * up the mode of the symlink `link_to_new.txt`, particularly * on platforms that don't support symlinks */ cl_git_pass(git_repository_index(&index, repo)); cl_git_pass(git_index_read(index, true)); cl_assert(idx_entry = git_index_get_bypath(index, "link_to_new.txt", 0)); cl_assert(S_ISLNK(idx_entry->mode)); git_index_free(index); git_object_free(head_object); git_reference_free(head); }
void test_config_read__read_git_config_entry(void) { git_config *cfg; git_config_entry *entry; cl_git_pass(git_config_new(&cfg)); cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"), GIT_CONFIG_LEVEL_SYSTEM, NULL, 0)); cl_git_pass(git_config_get_entry(&entry, cfg, "core.dummy2")); cl_assert_equal_s("core.dummy2", entry->name); cl_assert_equal_s("42", entry->value); cl_assert_equal_i(GIT_CONFIG_LEVEL_SYSTEM, entry->level); git_config_entry_free(entry); git_config_free(cfg); }
void test_index_filemodes__read(void) { git_index *index; unsigned int i; static bool expected[6] = { 0, 1, 0, 1, 0, 1 }; cl_git_pass(git_repository_index(&index, g_repo)); cl_assert_equal_i(6, (int)git_index_entrycount(index)); for (i = 0; i < 6; ++i) { const git_index_entry *entry = git_index_get_byindex(index, i); cl_assert(entry != NULL); cl_assert(((entry->mode & 0100) ? 1 : 0) == expected[i]); } git_index_free(index); }
void test_status_worktree__line_endings_dont_count_as_changes_with_autocrlf(void) { git_repository *repo = cl_git_sandbox_init("status"); unsigned int status; cl_repo_set_bool(repo, "core.autocrlf", true); cl_git_rewritefile("status/current_file", "current_file\r\n"); cl_git_pass(git_status_file(&status, repo, "current_file")); /* stat data on file should no longer match stat cache, even though * file diff will be empty because of line-ending conversion - matches * the Git command-line behavior here. */ cl_assert_equal_i(GIT_STATUS_WT_MODIFIED, status); }
void test_stash_apply__conflict_workdir_with_reinstate_index(void) { git_stash_apply_options opts = GIT_STASH_APPLY_OPTIONS_INIT; opts.flags = GIT_STASH_APPLY_REINSTATE_INDEX; cl_git_rewritefile("stash/what", "ciao\n"); cl_git_fail_with(git_stash_apply(repo, 0, &opts), GIT_ECONFLICT); cl_assert_equal_i(git_index_has_conflicts(repo_index), 0); assert_status(repo, "what", GIT_STATUS_WT_MODIFIED); assert_status(repo, "how", GIT_STATUS_CURRENT); assert_status(repo, "who", GIT_STATUS_CURRENT); assert_status(repo, "when", GIT_STATUS_WT_NEW); assert_status(repo, "why", GIT_ENOTFOUND); }
void test_object_blob_filter__unfiltered(void) { int i; git_blob *blob; for (i = 0; i < CRLF_NUM_TEST_OBJECTS; i++) { size_t raw_len = (size_t)g_crlf_raw_len[i]; cl_git_pass(git_blob_lookup(&blob, g_repo, &g_crlf_oids[i])); cl_assert_equal_sz(raw_len, (size_t)git_blob_rawsize(blob)); cl_assert_equal_i( 0, memcmp(g_crlf_raw[i], git_blob_rawcontent(blob), raw_len)); git_blob_free(blob); } }
void test_bsp__tree_can_clone(void) { bsp_node_t *cube_clone = clone_bsp_tree(cube_bsp); cl_assert(cube_clone != NULL); klist_t(poly) *clone_polys = bsp_to_polygons(cube_clone, 0, NULL); klist_t(poly) *orig_polys = bsp_to_polygons(cube_bsp, 0, NULL); cl_assert_equal_i(clone_polys->size, orig_polys->size); kl_destroy(poly, clone_polys); kl_destroy(poly, orig_polys); cl_assert(clone_polys != orig_polys); free_bsp_tree(cube_clone); }
void test_revwalk_basic__push_head_hide_ref_nobase(void) { int i = 0; git_oid oid; revwalk_basic_setup_walk(NULL); cl_git_pass(git_revwalk_push_head(_walk)); cl_git_pass(git_revwalk_hide_ref(_walk, "refs/heads/packed")); while (git_revwalk_next(&oid, _walk) == 0) { i++; } /* git log HEAD --oneline --not refs/heads/packed | wc -l => 7 */ cl_assert_equal_i(i, 7); }
void test_stash_apply__merges_new_file(void) { const git_index_entry *ancestor, *our, *their; cl_git_mkfile("stash/where", "committed before stash\n"); cl_git_pass(git_index_add_bypath(repo_index, "where")); cl_repo_commit_from_index(NULL, repo, signature, 0, "Other commit"); cl_git_pass(git_stash_apply(repo, 0, NULL)); cl_assert_equal_i(1, git_index_has_conflicts(repo_index)); assert_status(repo, "what", GIT_STATUS_INDEX_MODIFIED); cl_git_pass(git_index_conflict_get(&ancestor, &our, &their, repo_index, "where")); /* unmerged */ assert_status(repo, "who", GIT_STATUS_INDEX_MODIFIED); assert_status(repo, "when", GIT_STATUS_WT_NEW); assert_status(repo, "why", GIT_STATUS_INDEX_NEW); }
void test_online_fetch__ls_disconnected(void) { const git_remote_head **refs; size_t refs_len_before, refs_len_after; git_remote *remote; cl_git_pass(git_remote_create(&remote, _repo, "test", "http://github.com/libgit2/TestGitRepository.git")); cl_git_pass(git_remote_connect(remote, GIT_DIRECTION_FETCH)); cl_git_pass(git_remote_ls(&refs, &refs_len_before, remote)); git_remote_disconnect(remote); cl_git_pass(git_remote_ls(&refs, &refs_len_after, remote)); cl_assert_equal_i(refs_len_before, refs_len_after); git_remote_free(remote); }
void test_checkout_conflict__report_progress(void) { git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; git_vector paths = GIT_VECTOR_INIT; char *path; size_t i; struct checkout_index_entry checkout_index_entries[] = { { 0100644, CONFLICTING_ANCESTOR_OID, 1, "conflicting-1.txt" }, { 0100644, CONFLICTING_OURS_OID, 2, "conflicting-1.txt" }, { 0100644, CONFLICTING_THEIRS_OID, 3, "conflicting-1.txt" }, { 0100644, CONFLICTING_ANCESTOR_OID, 1, "conflicting-2.txt" }, { 0100644, CONFLICTING_OURS_OID, 2, "conflicting-2.txt" }, { 0100644, CONFLICTING_THEIRS_OID, 3, "conflicting-2.txt" }, { 0100644, AUTOMERGEABLE_ANCESTOR_OID, 1, "conflicting-3.txt" }, { 0100644, AUTOMERGEABLE_OURS_OID, 2, "conflicting-3.txt" }, { 0100644, AUTOMERGEABLE_THEIRS_OID, 3, "conflicting-3.txt" }, { 0100644, AUTOMERGEABLE_ANCESTOR_OID, 1, "conflicting-4.txt" }, { 0100644, AUTOMERGEABLE_OURS_OID, 2, "conflicting-4.txt" }, { 0100644, AUTOMERGEABLE_THEIRS_OID, 3, "conflicting-4.txt" }, }; opts.progress_cb = collect_progress; opts.progress_payload = &paths; create_index(checkout_index_entries, 12); git_index_write(g_index); cl_git_pass(git_checkout_index(g_repo, g_index, &opts)); cl_assert_equal_i(4, git_vector_length(&paths)); cl_assert_equal_s("conflicting-1.txt", git_vector_get(&paths, 0)); cl_assert_equal_s("conflicting-2.txt", git_vector_get(&paths, 1)); cl_assert_equal_s("conflicting-3.txt", git_vector_get(&paths, 2)); cl_assert_equal_s("conflicting-4.txt", git_vector_get(&paths, 3)); git_vector_foreach(&paths, i, path) git__free(path); git_vector_free(&paths); }
void test_odb_largefiles__streamread(void) { git_oid oid, read_oid; git_odb_stream *stream; char buf[10240]; char hdr[64]; size_t len, hdr_len, total = 0; git_hash_ctx hash; git_otype type; int ret; #ifndef GIT_ARCH_64 cl_skip(); #endif if (!cl_is_env_set("GITTEST_INVASIVE_FS_SIZE") || !cl_is_env_set("GITTEST_SLOW")) cl_skip(); writefile(&oid); cl_git_pass(git_odb_open_rstream(&stream, &len, &type, odb, &oid)); cl_assert_equal_sz(LARGEFILE_SIZE, len); cl_assert_equal_i(GIT_OBJ_BLOB, type); cl_git_pass(git_hash_ctx_init(&hash)); cl_git_pass(git_odb__format_object_header(&hdr_len, hdr, sizeof(hdr), len, type)); cl_git_pass(git_hash_update(&hash, hdr, hdr_len)); while ((ret = git_odb_stream_read(stream, buf, 10240)) > 0) { cl_git_pass(git_hash_update(&hash, buf, ret)); total += ret; } cl_assert_equal_sz(LARGEFILE_SIZE, total); git_hash_final(&read_oid, &hash); cl_assert_equal_oid(&oid, &read_oid); git_hash_ctx_cleanup(&hash); git_odb_stream_free(stream); }
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_object_blob_filter__stats(void) { int i; git_blob *blob; git_buf buf = GIT_BUF_INIT; git_buf_text_stats stats; for (i = 0; i < CRLF_NUM_TEST_OBJECTS; i++) { cl_git_pass(git_blob_lookup(&blob, g_repo, &g_crlf_oids[i])); cl_git_pass(git_blob__getbuf(&buf, blob)); git_buf_text_gather_stats(&stats, &buf, false); cl_assert_equal_i( 0, memcmp(&g_crlf_filtered_stats[i], &stats, sizeof(stats))); git_blob_free(blob); } git_buf_free(&buf); }
static void test_win32_name(const char *name) { git_reference *new_reference = NULL; git_oid id; int ret; git_oid_fromstr(&id, current_master_tip); ret = git_reference_create(&new_reference, g_repo, name, &id, 0, NULL); #ifdef GIT_WIN32 cl_assert_equal_i(GIT_EINVALIDSPEC, ret); #else cl_git_pass(ret); #endif git_reference_free(new_reference); }
void test_network_remote_rename__renamed_name_is_persisted(void) { git_remote *renamed; git_repository *another_repo; git_strarray problems = {0}; cl_git_fail(git_remote_lookup(&renamed, _repo, "just/renamed")); cl_git_pass(git_remote_rename(&problems, _repo, _remote_name, "just/renamed")); cl_assert_equal_i(0, problems.count); git_strarray_free(&problems); cl_git_pass(git_repository_open(&another_repo, "testrepo.git")); cl_git_pass(git_remote_lookup(&renamed, _repo, "just/renamed")); git_remote_free(renamed); git_repository_free(another_repo); }
void test_repo_head__set_to_current_target(void) { git_reflog *log; size_t nentries, nentries_after; cl_git_pass(git_reflog_read(&log, repo, GIT_HEAD_FILE)); nentries = git_reflog_entrycount(log); git_reflog_free(log); cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked")); cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked")); cl_git_pass(git_reflog_read(&log, repo, GIT_HEAD_FILE)); nentries_after = git_reflog_entrycount(log); git_reflog_free(log); cl_assert_equal_i(nentries + 1, nentries_after); }
static void test_read_header(object_data *data) { git_oid id; git_odb *odb; size_t len; git_object_t type; write_object_files(data); cl_git_pass(git_odb_open(&odb, "test-objects")); cl_git_pass(git_oid_fromstr(&id, data->id)); cl_git_pass(git_odb_read_header(&len, &type, odb, &id)); cl_assert_equal_sz(data->dlen, len); cl_assert_equal_i(git_object_string2type(data->type), type); git_odb_free(odb); }
static void ensure_workdir_mode(const char *path, int mode) { #ifdef GIT_WIN32 GIT_UNUSED(path); GIT_UNUSED(mode); #else git_buf fullpath = GIT_BUF_INIT; struct stat st; cl_git_pass( git_buf_joinpath(&fullpath, git_repository_workdir(g_repo), path)); cl_git_pass(p_stat(git_buf_cstr(&fullpath), &st)); cl_assert_equal_i((mode & S_IRWXU), (st.st_mode & S_IRWXU)); git_buf_free(&fullpath); #endif }
void test_revwalk_mergebase__no_common_ancestor_returns_ENOTFOUND(void) { git_oid result, one, two; size_t ahead, behind; int error; cl_git_pass(git_oid_fromstr(&one, "763d71aadf09a7951596c9746c024e7eece7c7af")); cl_git_pass(git_oid_fromstr(&two, "e90810b8df3e80c413d903f631643c716887138d")); error = git_merge_base(&result, _repo, &one, &two); cl_git_fail(error); cl_assert_equal_i(GIT_ENOTFOUND, error); cl_git_pass(git_graph_ahead_behind(&ahead, &behind, _repo, &one, &two)); cl_assert_equal_sz(2, ahead); cl_assert_equal_sz(4, behind); }
void test_stash_apply__conflict_index_with_default(void) { const git_index_entry *ancestor; const git_index_entry *our; const git_index_entry *their; cl_git_rewritefile("stash/who", "nothing\n"); cl_git_pass(git_index_add_bypath(repo_index, "who")); cl_git_pass(git_index_write(repo_index)); cl_git_pass(git_stash_apply(repo, 0, NULL)); cl_assert_equal_i(git_index_has_conflicts(repo_index), 1); assert_status(repo, "what", GIT_STATUS_INDEX_MODIFIED); assert_status(repo, "how", GIT_STATUS_CURRENT); cl_git_pass(git_index_conflict_get(&ancestor, &our, &their, repo_index, "who")); /* unmerged */ assert_status(repo, "when", GIT_STATUS_WT_NEW); }
void test_network_remotelocal__retrieve_advertised_references_from_spaced_repository(void) { int how_many_refs = 0; cl_fixture_sandbox("testrepo.git"); cl_git_pass(p_rename("testrepo.git", "spaced testrepo.git")); connect_to_local_repository("spaced testrepo.git"); cl_git_pass(git_remote_ls(remote, &count_ref__cb, &how_many_refs)); cl_assert_equal_i(how_many_refs, 26); git_remote_free(remote); /* Disconnect from the "spaced repo" before the cleanup */ remote = NULL; cl_fixture_cleanup("spaced testrepo.git"); }
void test_config_configlevel__adding_the_same_level_twice_returns_EEXISTS(void) { int error; git_config *cfg; cl_git_pass(git_config_new(&cfg)); cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config9"), GIT_CONFIG_LEVEL_LOCAL, 0)); cl_git_pass(git_config_add_file_ondisk(cfg, cl_fixture("config/config15"), GIT_CONFIG_LEVEL_GLOBAL, 0)); error = git_config_add_file_ondisk(cfg, cl_fixture("config/config16"), GIT_CONFIG_LEVEL_GLOBAL, 0); cl_git_fail(error); cl_assert_equal_i(GIT_EEXISTS, error); git_config_free(cfg); }
void test_stash_apply__uses_reflog_like_indices_1(void) { git_oid oid; cl_git_mkfile("stash/untracked", "untracked\n"); cl_git_pass(git_stash_save(&oid, repo, signature, NULL, GIT_STASH_INCLUDE_UNTRACKED)); assert_status(repo, "untracked", GIT_ENOTFOUND); // stash@{1} is the oldest (first) stash we made cl_git_pass(git_stash_apply(repo, 1, NULL)); cl_assert_equal_i(git_index_has_conflicts(repo_index), 0); assert_status(repo, "what", GIT_STATUS_WT_MODIFIED); assert_status(repo, "how", GIT_STATUS_CURRENT); assert_status(repo, "who", GIT_STATUS_WT_MODIFIED); assert_status(repo, "when", GIT_STATUS_WT_NEW); assert_status(repo, "why", GIT_STATUS_INDEX_NEW); assert_status(repo, "where", GIT_STATUS_INDEX_NEW); }
void test_refs_branches_create__cannot_force_create_over_current_branch(void) { const git_oid *oid; git_reference *branch2; retrieve_known_commit(&target, repo); cl_git_pass(git_branch_lookup(&branch2, repo, "master", GIT_BRANCH_LOCAL)); cl_assert_equal_s("refs/heads/master", git_reference_name(branch2)); cl_assert_equal_i(true, git_branch_is_head(branch2)); oid = git_reference_target(branch2); cl_git_fail_with(-1, git_branch_create(&branch, repo, "master", target, 1, NULL, NULL)); branch = NULL; cl_git_pass(git_branch_lookup(&branch, repo, "master", GIT_BRANCH_LOCAL)); cl_assert_equal_s("refs/heads/master", git_reference_name(branch)); cl_git_pass(git_oid_cmp(git_reference_target(branch), oid)); git_reference_free(branch2); }
void test_revwalk_basic__push_all(void) { git_oid oid; int i = 0; revwalk_basic_setup_walk(NULL); git_revwalk_reset(_walk); git_revwalk_sorting(_walk, 0); cl_git_pass(git_revwalk_push_glob(_walk, "*")); while (git_revwalk_next(&oid, _walk) == 0) { i++; } /* git rev-list --count --all #=> 15 */ cl_assert_equal_i(15, i); }
void test_revwalk_basic__push_mixed(void) { git_oid oid; int i = 0; revwalk_basic_setup_walk(NULL); git_revwalk_reset(_walk); git_revwalk_sorting(_walk, 0); cl_git_pass(git_revwalk_push_glob(_walk, "tags")); while (git_revwalk_next(&oid, _walk) == 0) { i++; } /* git rev-list --count --glob=tags #=> 9 */ cl_assert_equal_i(9, i); }
void test_stash_drop__dropping_the_top_stash_updates_the_stash_reference(void) { git_object *next_top_stash; git_oid oid; push_three_states(); retrieve_top_stash_id(&oid); cl_git_pass(git_revparse_single(&next_top_stash, repo, "stash@{1}")); cl_assert_equal_i(false, git_oid_cmp(&oid, git_object_id(next_top_stash)) == 0); cl_git_pass(git_stash_drop(repo, 0)); retrieve_top_stash_id(&oid); cl_git_pass(git_oid_cmp(&oid, git_object_id(next_top_stash))); }
void test_diff_parse__get_patch_from_diff(void) { git_repository *repo; git_diff *computed, *parsed; git_tree *a, *b; git_diff_options opts = GIT_DIFF_OPTIONS_INIT; git_buf computed_buf = GIT_BUF_INIT; git_patch *patch_computed, *patch_parsed; repo = cl_git_sandbox_init("diff"); opts.flags = GIT_DIFF_SHOW_BINARY; cl_assert((a = resolve_commit_oid_to_tree(repo, "d70d245ed97ed2aa596dd1af6536e4bfdb047b69")) != NULL); cl_assert((b = resolve_commit_oid_to_tree(repo, "7a9e0b02e63179929fed24f0a3e0f19168114d10")) != NULL); cl_git_pass(git_diff_tree_to_tree(&computed, repo, a, b, &opts)); cl_git_pass(git_diff_to_buf(&computed_buf, computed, GIT_DIFF_FORMAT_PATCH)); cl_git_pass(git_patch_from_diff(&patch_computed, computed, 0)); cl_git_pass(git_diff_from_buffer(&parsed, computed_buf.ptr, computed_buf.size)); cl_git_pass(git_patch_from_diff(&patch_parsed, parsed, 0)); cl_assert_equal_i( git_patch_num_hunks(patch_computed), git_patch_num_hunks(patch_parsed)); git_patch_free(patch_computed); git_patch_free(patch_parsed); git_tree_free(a); git_tree_free(b); git_diff_free(computed); git_diff_free(parsed); git_buf_free(&computed_buf); cl_git_sandbox_cleanup(); }