void test_submodule_update__update_and_init_submodule(void) { git_submodule *sm; git_submodule_update_options update_options = GIT_SUBMODULE_UPDATE_OPTIONS_INIT; unsigned int submodule_status = 0; g_repo = setup_fixture_submodule_simple(); /* get the submodule */ cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo")); cl_git_pass(git_submodule_status(&submodule_status, sm)); cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD | GIT_SUBMODULE_STATUS_IN_INDEX | GIT_SUBMODULE_STATUS_IN_CONFIG | GIT_SUBMODULE_STATUS_WD_UNINITIALIZED); /* update (with option to initialize sub repo) */ cl_git_pass(git_submodule_update(sm, 1, &update_options)); /* verify expected state */ cl_assert(git_oid_streq(git_submodule_head_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0); cl_assert(git_oid_streq(git_submodule_wd_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0); cl_assert(git_oid_streq(git_submodule_index_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0); git_submodule_free(sm); }
static void assert_content_in_index( git_strarray *pathspecs, bool should_exist, git_strarray *expected_shas) { size_t i, pos; int error; for (i = 0; i < pathspecs->count; i++) { error = git_index_find(&pos, _index, pathspecs->strings[i]); if (should_exist) { const git_index_entry *entry; cl_assert(error != GIT_ENOTFOUND); entry = git_index_get_byindex(_index, pos); cl_assert(entry != NULL); if (!expected_shas) continue; cl_git_pass(git_oid_streq(&entry->oid, expected_shas->strings[i])); } else cl_assert_equal_i(should_exist, error != GIT_ENOTFOUND); } }
void test_refs_reflog_messages__creating_a_direct_reference(void) { git_reference *reference; git_oid id; git_reflog *reflog; const git_reflog_entry *entry; const char *name = "refs/heads/new-head"; const char *message = "You've been logged, mate!"; cl_git_pass(git_reference_name_to_id(&id, g_repo, "HEAD")); cl_git_pass(git_reference_create(&reference, g_repo, name, &id, 0, message)); cl_git_pass(git_reflog_read(&reflog, g_repo, name)); cl_assert_equal_sz(1, git_reflog_entrycount(reflog)); entry = git_reflog_entry_byindex(reflog, 0); cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) == 0); cl_assert_equal_oid(&id, &entry->oid_cur); cl_assert_equal_s(message, entry->msg); git_reflog_free(reflog); git_reference_free(reference); }
void test_refs_branches_create__creating_a_branch_targeting_a_tag_dereferences_it_to_its_commit(void) { /* b25fa35 is a tag, pointing to another tag which points to a commit */ retrieve_target_from_oid(&target, repo, "b25fa35b38051e4ae45d4222e795f9df2e43f1d1"); cl_git_pass(git_branch_create(&branch_target_oid, repo, NEW_BRANCH_NAME, target, 0)); cl_git_pass(git_oid_streq(&branch_target_oid, "e90810b8df3e80c413d903f631643c716887138d")); }
void test_submodule_update__update_submodule(void) { git_submodule *sm; git_submodule_update_options update_options = GIT_SUBMODULE_UPDATE_OPTIONS_INIT; unsigned int submodule_status = 0; struct update_submodule_cb_payload update_payload = { 0 }; g_repo = setup_fixture_submodule_simple(); update_options.checkout_opts.progress_cb = checkout_progress_cb; update_options.checkout_opts.progress_payload = &update_payload; update_options.remote_callbacks.update_tips = update_tips; update_options.remote_callbacks.payload = &update_payload; /* get the submodule */ cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo")); /* verify the initial state of the submodule */ cl_git_pass(git_submodule_status(&submodule_status, sm)); cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD | GIT_SUBMODULE_STATUS_IN_INDEX | GIT_SUBMODULE_STATUS_IN_CONFIG | GIT_SUBMODULE_STATUS_WD_UNINITIALIZED); /* initialize and update the submodule */ cl_git_pass(git_submodule_init(sm, 0)); cl_git_pass(git_submodule_update(sm, 0, &update_options)); /* verify state */ cl_git_pass(git_submodule_status(&submodule_status, sm)); cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD | GIT_SUBMODULE_STATUS_IN_INDEX | GIT_SUBMODULE_STATUS_IN_CONFIG | GIT_SUBMODULE_STATUS_IN_WD); cl_assert(git_oid_streq(git_submodule_head_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0); cl_assert(git_oid_streq(git_submodule_wd_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0); cl_assert(git_oid_streq(git_submodule_index_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0); /* verify that the expected callbacks have been called. */ cl_assert_equal_i(1, update_payload.checkout_progress_called); cl_assert_equal_i(1, update_payload.update_tips_called); git_submodule_free(sm); }
static void assert_blob_creation(const char *path_to_file, const char *blob_from_path, blob_creator_fn creator) { git_oid oid; cl_git_mkfile(path_to_file, "1..2...3... Can you hear me?\n"); cl_must_pass(creator(&oid, repo, blob_from_path)); cl_assert(git_oid_streq(&oid, "da5e4f20c91c81b44a7e298f3d3fb3fe2f178e32") == 0); }
static void assert_reset_soft(bool should_be_detached) { git_oid oid; cl_git_pass(git_reference_name_to_id(&oid, repo, "HEAD")); cl_git_fail(git_oid_streq(&oid, KNOWN_COMMIT_IN_BARE_REPO)); retrieve_target_from_oid(&target, repo, KNOWN_COMMIT_IN_BARE_REPO); cl_assert(git_repository_head_detached(repo) == should_be_detached); cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT)); cl_assert(git_repository_head_detached(repo) == should_be_detached); cl_git_pass(git_reference_name_to_id(&oid, repo, "HEAD")); cl_git_pass(git_oid_streq(&oid, KNOWN_COMMIT_IN_BARE_REPO)); }
static int ensure_peeled__cb(git_remote_head *head, void *payload) { GIT_UNUSED(payload); if(strcmp(head->name, "refs/tags/test^{}") != 0) return 0; return git_oid_streq(&head->oid, "e90810b8df3e80c413d903f631643c716887138d"); }
void test_revwalk_basic__mimic_git_rev_list(void) { git_oid oid; revwalk_basic_setup_walk(NULL); git_revwalk_sorting(_walk, GIT_SORT_TIME); cl_git_pass(git_revwalk_push_ref(_walk, "refs/heads/br2")); cl_git_pass(git_revwalk_push_ref(_walk, "refs/heads/master")); cl_git_pass(git_oid_fromstr(&oid, "e90810b8df3e80c413d903f631643c716887138d")); cl_git_pass(git_revwalk_push(_walk, &oid)); cl_git_pass(git_revwalk_next(&oid, _walk)); cl_assert(!git_oid_streq(&oid, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750")); cl_git_pass(git_revwalk_next(&oid, _walk)); cl_assert(!git_oid_streq(&oid, "e90810b8df3e80c413d903f631643c716887138d")); cl_git_pass(git_revwalk_next(&oid, _walk)); cl_assert(!git_oid_streq(&oid, "6dcf9bf7541ee10456529833502442f385010c3d")); cl_git_pass(git_revwalk_next(&oid, _walk)); cl_assert(!git_oid_streq(&oid, "a4a7dce85cf63874e984719f4fdd239f5145052f")); cl_git_pass(git_revwalk_next(&oid, _walk)); cl_assert(!git_oid_streq(&oid, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644")); cl_git_pass(git_revwalk_next(&oid, _walk)); cl_assert(!git_oid_streq(&oid, "c47800c7266a2be04c571c04d5a6614691ea99bd")); cl_git_pass(git_revwalk_next(&oid, _walk)); cl_assert(!git_oid_streq(&oid, "9fd738e8f7967c078dceed8190330fc8648ee56a")); cl_git_pass(git_revwalk_next(&oid, _walk)); cl_assert(!git_oid_streq(&oid, "4a202b346bb0fb0db7eff3cffeb3c70babbd2045")); cl_git_pass(git_revwalk_next(&oid, _walk)); cl_assert(!git_oid_streq(&oid, "5b5b025afb0b4c913b4c338a42934a3863bf3644")); cl_git_pass(git_revwalk_next(&oid, _walk)); cl_assert(!git_oid_streq(&oid, "8496071c1b46c854b31185ea97743be6a8774479")); cl_git_fail_with(git_revwalk_next(&oid, _walk), GIT_ITEROVER); }
static int test_checkout_notify_cb( git_checkout_notify_t why, const char *path, const git_diff_file *baseline, const git_diff_file *target, const git_diff_file *workdir, void *payload) { struct notify_data *expectations = (struct notify_data *)payload; GIT_UNUSED(workdir); cl_assert_equal_i(GIT_CHECKOUT_NOTIFY_CONFLICT, why); cl_assert_equal_s(expectations->file, path); cl_assert_equal_i(0, git_oid_streq(&baseline->oid, expectations->sha)); cl_assert_equal_i(0, git_oid_streq(&target->oid, expectations->sha)); return 0; }
static void check_tree_entry( git_iterator *i, const char *oid, const char *oid_p, const char *oid_pp, const char *oid_ppp) { const git_index_entry *ie; const git_tree_entry *te; const git_tree *tree; git_buf path = GIT_BUF_INIT; cl_git_pass(git_iterator_current_tree_entry(&te, i)); cl_assert(te); cl_assert(git_oid_streq(te->oid, oid) == 0); cl_git_pass(git_iterator_current(&ie, i)); cl_git_pass(git_buf_sets(&path, ie->path)); if (oid_p) { git_buf_rtruncate_at_char(&path, '/'); cl_git_pass(git_iterator_current_parent_tree(&tree, i, path.ptr)); cl_assert(tree); cl_assert(git_oid_streq(git_tree_id(tree), oid_p) == 0); } if (oid_pp) { git_buf_rtruncate_at_char(&path, '/'); cl_git_pass(git_iterator_current_parent_tree(&tree, i, path.ptr)); cl_assert(tree); cl_assert(git_oid_streq(git_tree_id(tree), oid_pp) == 0); } if (oid_ppp) { git_buf_rtruncate_at_char(&path, '/'); cl_git_pass(git_iterator_current_parent_tree(&tree, i, path.ptr)); cl_assert(tree); cl_assert(git_oid_streq(git_tree_id(tree), oid_ppp) == 0); } git_buf_free(&path); }
void test_refs_reflog_drop__can_drop_the_oldest_entry(void) { const git_reflog_entry *entry; cl_assert(entrycount > 2); cl_git_pass(git_reflog_drop(g_reflog, entrycount - 1, 0)); cl_assert_equal_sz(entrycount - 1, git_reflog_entrycount(g_reflog)); entry = git_reflog_entry_byindex(g_reflog, entrycount - 2); cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) != 0); }
void test_refs_reflog_drop__can_drop_the_oldest_entry_and_rewrite_the_log_history(void) { const git_reflog_entry *entry; cl_assert(entrycount > 2); cl_git_pass(git_reflog_drop(g_reflog, 0, 1)); cl_assert_equal_i(entrycount - 1, git_reflog_entrycount(g_reflog)); entry = git_reflog_entry_byindex(g_reflog, 0); cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) == 0); }
void test_reset_soft__resetting_to_a_tag_sets_the_Head_to_the_peeled_commit(void) { git_oid oid; /* b25fa35 is a tag, pointing to another tag which points to commit e90810b */ retrieve_target_from_oid(&target, repo, "b25fa35b38051e4ae45d4222e795f9df2e43f1d1"); cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT)); cl_assert(git_repository_head_detached(repo) == false); cl_git_pass(git_reference_name_to_id(&oid, repo, "HEAD")); cl_git_pass(git_oid_streq(&oid, KNOWN_COMMIT_IN_BARE_REPO)); }
static void assert_proper_normalization(git_index *index, const char *filename, const char *expected_sha) { size_t index_pos; const git_index_entry *entry; add_to_workdir(filename, CONTENT); cl_git_pass(git_index_add_bypath(index, filename)); cl_assert(!git_index_find(&index_pos, index, filename)); entry = git_index_get_byindex(index, index_pos); cl_assert_equal_i(0, git_oid_streq(&entry->oid, expected_sha)); }
static void assert_proper_normalization(git_index *index, const char *filename, const char *expected_sha) { int index_pos; git_index_entry *entry; add_to_workdir(filename, CONTENT); cl_git_pass(git_index_add_from_workdir(index, filename)); index_pos = git_index_find(index, filename); cl_assert(index_pos >= 0); entry = git_index_get_byindex(index, index_pos); cl_assert_equal_i(0, git_oid_streq(&entry->oid, expected_sha)); }
void test_network_remote_local__nested_tags_are_completely_peeled(void) { const git_remote_head **refs; size_t refs_len, i; connect_to_local_repository(cl_fixture("testrepo.git")); cl_git_pass(git_remote_ls(&refs, &refs_len, remote)); for (i = 0; i < refs_len; i++) { if (!strcmp(refs[i]->name, "refs/tags/test^{}")) cl_git_pass(git_oid_streq(&refs[i]->oid, "e90810b8df3e80c413d903f631643c716887138d")); } }
static int notify_cb( const char *skipped_file, const git_oid *blob_oid, int file_mode, void *payload) { struct notify_data *expectations = (struct notify_data *)payload; GIT_UNUSED(file_mode); cl_assert_equal_s(expectations->file, skipped_file); cl_assert_equal_i(0, git_oid_streq(blob_oid, expectations->sha)); return 0; }
static void assert_nth_gen_parent(unsigned int gen, const char *expected_oid) { git_commit *parent = NULL; int error; error = git_commit_nth_gen_ancestor(&parent, commit, gen); if (expected_oid != NULL) { cl_assert_equal_i(0, error); cl_assert_equal_i(0, git_oid_streq(git_commit_id(parent), expected_oid)); } else cl_assert_equal_i(GIT_ENOTFOUND, error); git_commit_free(parent); }
static int callback_cb( size_t index, const char* message, const git_oid *stash_oid, void *payload) { struct callback_data *data = (struct callback_data *)payload; GIT_UNUSED(index); GIT_UNUSED(message); cl_assert_equal_i(0, git_oid_streq(stash_oid, data->oids[data->invokes++])); return 0; }
void test_reset_soft__resetting_to_the_commit_pointed_at_by_the_Head_does_not_change_the_target_of_the_Head(void) { git_oid oid; char raw_head_oid[GIT_OID_HEXSZ + 1]; cl_git_pass(git_reference_name_to_id(&oid, repo, "HEAD")); git_oid_fmt(raw_head_oid, &oid); raw_head_oid[GIT_OID_HEXSZ] = '\0'; retrieve_target_from_oid(&target, repo, raw_head_oid); cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT)); cl_git_pass(git_reference_name_to_id(&oid, repo, "HEAD")); cl_git_pass(git_oid_streq(&oid, raw_head_oid)); }
static void assert_object_oid(const char* revision, const char* expected_oid, git_otype type) { int result; git_object *obj; result = git_revparse_single(&obj, repo, revision); if (!expected_oid) { cl_assert_equal_i(GIT_ENOTFOUND, result); return; } else cl_assert_equal_i(0, result); cl_git_pass(git_oid_streq(git_object_id(obj), expected_oid)); cl_assert_equal_i(type, git_object_type(obj)); git_object_free(obj); }
void test_reset_soft__resetting_against_an_orphaned_head_repo_makes_the_head_no_longer_orphaned(void) { git_reference *head; retrieve_target_from_oid(&target, repo, KNOWN_COMMIT_IN_BARE_REPO); make_head_orphaned(repo, NON_EXISTING_HEAD); cl_assert_equal_i(true, git_repository_head_orphan(repo)); cl_git_pass(git_reset(repo, target, GIT_RESET_SOFT)); cl_assert_equal_i(false, git_repository_head_orphan(repo)); cl_git_pass(git_reference_lookup(&head, repo, NON_EXISTING_HEAD)); cl_assert_equal_i(0, git_oid_streq(git_reference_target(head), KNOWN_COMMIT_IN_BARE_REPO)); git_reference_free(head); }
static void assert_appends(const git_signature *committer, const git_oid *oid) { git_repository *repo2; git_reference *lookedup_ref; git_reflog *reflog; const git_reflog_entry *entry; /* Reopen a new instance of the repository */ cl_git_pass(git_repository_open(&repo2, "testrepo.git")); /* Lookup the previously created branch */ cl_git_pass(git_reference_lookup(&lookedup_ref, repo2, new_ref)); /* Read and parse the reflog for this branch */ cl_git_pass(git_reflog_read(&reflog, repo2, new_ref)); cl_assert_equal_i(3, (int)git_reflog_entrycount(reflog)); /* The first one was the creation of the branch */ entry = git_reflog_entry_byindex(reflog, 2); cl_assert(git_oid_streq(&entry->oid_old, GIT_OID_HEX_ZERO) == 0); entry = git_reflog_entry_byindex(reflog, 1); assert_signature(committer, entry->committer); cl_assert(git_oid_cmp(oid, &entry->oid_old) == 0); cl_assert(git_oid_cmp(oid, &entry->oid_cur) == 0); cl_assert(entry->msg == NULL); entry = git_reflog_entry_byindex(reflog, 0); assert_signature(committer, entry->committer); cl_assert(git_oid_cmp(oid, &entry->oid_cur) == 0); cl_assert_equal_s(commit_msg, entry->msg); git_reflog_free(reflog); git_repository_free(repo2); git_reference_free(lookedup_ref); }
void test_odb_loose__exists(void) { git_oid id, id2; git_odb *odb; write_object_files(&one); cl_git_pass(git_odb_open(&odb, "test-objects")); cl_git_pass(git_oid_fromstr(&id, one.id)); cl_assert(git_odb_exists(odb, &id)); cl_git_pass(git_oid_fromstrp(&id, "8b137891")); cl_git_pass(git_odb_exists_prefix(&id2, odb, &id, 8)); cl_assert_equal_i(0, git_oid_streq(&id2, one.id)); /* Test for a missing object */ cl_git_pass(git_oid_fromstr(&id, "8b137891791fe96927ad78e64b0aad7bded08baa")); cl_assert(!git_odb_exists(odb, &id)); cl_git_pass(git_oid_fromstrp(&id, "8b13789a")); cl_assert_equal_i(GIT_ENOTFOUND, git_odb_exists_prefix(&id2, odb, &id, 8)); git_odb_free(odb); }
void test_submodule_update__update_already_checked_out_submodule(void) { git_submodule *sm = NULL; git_checkout_options checkout_options = GIT_CHECKOUT_OPTIONS_INIT; git_submodule_update_options update_options = GIT_SUBMODULE_UPDATE_OPTIONS_INIT; unsigned int submodule_status = 0; git_reference *branch_reference = NULL; git_object *branch_commit = NULL; struct update_submodule_cb_payload update_payload = { 0 }; g_repo = setup_fixture_submodule_simple(); update_options.checkout_opts.progress_cb = checkout_progress_cb; update_options.checkout_opts.progress_payload = &update_payload; /* Initialize and update the sub repository */ cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo")); cl_git_pass(git_submodule_status(&submodule_status, sm)); cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD | GIT_SUBMODULE_STATUS_IN_INDEX | GIT_SUBMODULE_STATUS_IN_CONFIG | GIT_SUBMODULE_STATUS_WD_UNINITIALIZED); cl_git_pass(git_submodule_update(sm, 1, &update_options)); /* verify expected state */ cl_assert(git_oid_streq(git_submodule_head_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0); cl_assert(git_oid_streq(git_submodule_wd_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0); cl_assert(git_oid_streq(git_submodule_index_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0); /* checkout the alternate_1 branch */ checkout_options.checkout_strategy = GIT_CHECKOUT_SAFE; cl_git_pass(git_reference_lookup(&branch_reference, g_repo, "refs/heads/alternate_1")); cl_git_pass(git_reference_peel(&branch_commit, branch_reference, GIT_OBJ_COMMIT)); cl_git_pass(git_checkout_tree(g_repo, branch_commit, &checkout_options)); cl_git_pass(git_repository_set_head(g_repo, git_reference_name(branch_reference))); /* * Verify state after checkout of parent repository. The submodule ID in the * HEAD commit and index should be updated, but not the workdir. */ cl_git_pass(git_submodule_status(&submodule_status, sm)); cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD | GIT_SUBMODULE_STATUS_IN_INDEX | GIT_SUBMODULE_STATUS_IN_CONFIG | GIT_SUBMODULE_STATUS_IN_WD | GIT_SUBMODULE_STATUS_WD_MODIFIED); cl_assert(git_oid_streq(git_submodule_head_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0); cl_assert(git_oid_streq(git_submodule_wd_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0); cl_assert(git_oid_streq(git_submodule_index_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0); /* * Update the submodule and verify the state. * Now, the HEAD, index, and Workdir commits should all be updated to * the new commit. */ cl_git_pass(git_submodule_update(sm, 0, &update_options)); cl_assert(git_oid_streq(git_submodule_head_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0); cl_assert(git_oid_streq(git_submodule_wd_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0); cl_assert(git_oid_streq(git_submodule_index_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0); /* verify that the expected callbacks have been called. */ cl_assert_equal_i(1, update_payload.checkout_progress_called); git_submodule_free(sm); git_object_free(branch_commit); git_reference_free(branch_reference); }
void test_submodule_lookup__accessors(void) { git_submodule *sm; const char *oid = "480095882d281ed676fe5b863569520e54a7d5c0"; cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged")); cl_assert(git_submodule_owner(sm) == g_repo); cl_assert_equal_s("sm_unchanged", git_submodule_name(sm)); cl_assert(git__suffixcmp(git_submodule_path(sm), "sm_unchanged") == 0); cl_assert(git__suffixcmp(git_submodule_url(sm), "/submod2_target") == 0); cl_assert(git_oid_streq(git_submodule_index_id(sm), oid) == 0); cl_assert(git_oid_streq(git_submodule_head_id(sm), oid) == 0); cl_assert(git_oid_streq(git_submodule_wd_id(sm), oid) == 0); cl_assert(git_submodule_ignore(sm) == GIT_SUBMODULE_IGNORE_NONE); cl_assert(git_submodule_update(sm) == GIT_SUBMODULE_UPDATE_CHECKOUT); git_submodule_free(sm); cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_changed_head")); cl_assert_equal_s("sm_changed_head", git_submodule_name(sm)); cl_assert(git_oid_streq(git_submodule_index_id(sm), oid) == 0); cl_assert(git_oid_streq(git_submodule_head_id(sm), oid) == 0); cl_assert(git_oid_streq(git_submodule_wd_id(sm), "3d9386c507f6b093471a3e324085657a3c2b4247") == 0); git_submodule_free(sm); cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_added_and_uncommited")); cl_assert_equal_s("sm_added_and_uncommited", git_submodule_name(sm)); cl_assert(git_oid_streq(git_submodule_index_id(sm), oid) == 0); cl_assert(git_submodule_head_id(sm) == NULL); cl_assert(git_oid_streq(git_submodule_wd_id(sm), oid) == 0); git_submodule_free(sm); cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_missing_commits")); cl_assert_equal_s("sm_missing_commits", git_submodule_name(sm)); cl_assert(git_oid_streq(git_submodule_index_id(sm), oid) == 0); cl_assert(git_oid_streq(git_submodule_head_id(sm), oid) == 0); cl_assert(git_oid_streq(git_submodule_wd_id(sm), "5e4963595a9774b90524d35a807169049de8ccad") == 0); git_submodule_free(sm); }
void test_submodule_update__can_force_update(void) { git_submodule *sm = NULL; git_checkout_options checkout_options = GIT_CHECKOUT_OPTIONS_INIT; git_submodule_update_options update_options = GIT_SUBMODULE_UPDATE_OPTIONS_INIT; unsigned int submodule_status = 0; git_reference *branch_reference = NULL; git_object *branch_commit = NULL; g_repo = setup_fixture_submodule_simple(); /* Initialize and update the sub repository */ cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo")); cl_git_pass(git_submodule_status(&submodule_status, sm)); cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD | GIT_SUBMODULE_STATUS_IN_INDEX | GIT_SUBMODULE_STATUS_IN_CONFIG | GIT_SUBMODULE_STATUS_WD_UNINITIALIZED); cl_git_pass(git_submodule_update(sm, 1, &update_options)); /* verify expected state */ cl_assert(git_oid_streq(git_submodule_head_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0); cl_assert(git_oid_streq(git_submodule_wd_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0); cl_assert(git_oid_streq(git_submodule_index_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0); /* checkout the alternate_1 branch */ checkout_options.checkout_strategy = GIT_CHECKOUT_SAFE; cl_git_pass(git_reference_lookup(&branch_reference, g_repo, "refs/heads/alternate_1")); cl_git_pass(git_reference_peel(&branch_commit, branch_reference, GIT_OBJ_COMMIT)); cl_git_pass(git_checkout_tree(g_repo, branch_commit, &checkout_options)); cl_git_pass(git_repository_set_head(g_repo, git_reference_name(branch_reference))); /* * Verify state after checkout of parent repository. The submodule ID in the * HEAD commit and index should be updated, but not the workdir. */ cl_git_pass(git_submodule_status(&submodule_status, sm)); cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_HEAD | GIT_SUBMODULE_STATUS_IN_INDEX | GIT_SUBMODULE_STATUS_IN_CONFIG | GIT_SUBMODULE_STATUS_IN_WD | GIT_SUBMODULE_STATUS_WD_MODIFIED); cl_assert(git_oid_streq(git_submodule_head_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0); cl_assert(git_oid_streq(git_submodule_wd_id(sm), "be3563ae3f795b2b4353bcce3a527ad0a4f7f644") == 0); cl_assert(git_oid_streq(git_submodule_index_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0); /* * Create a conflicting edit in the subrepository to verify that * the submodule update action is blocked. */ cl_git_write2file("submodule_simple/testrepo/branch_file.txt", "a conflicting edit", 0, O_WRONLY | O_CREAT | O_TRUNC, 0777); /* forcefully checkout and verify the submodule state was updated. */ update_options.checkout_opts.checkout_strategy = GIT_CHECKOUT_FORCE; cl_git_pass(git_submodule_update(sm, 0, &update_options)); cl_assert(git_oid_streq(git_submodule_head_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0); cl_assert(git_oid_streq(git_submodule_wd_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0); cl_assert(git_oid_streq(git_submodule_index_id(sm), "a65fedf39aefe402d3bb6e24df4d4f5fe4547750") == 0); git_submodule_free(sm); git_object_free(branch_commit); git_reference_free(branch_reference); }