void test_refs_overwrite__object_id(void) { // Overwrite an existing object id reference git_reference *ref; git_oid id; cl_git_pass(git_reference_lookup(&ref, g_repo, ref_master_name)); cl_assert(git_reference_type(ref) & GIT_REF_OID); git_oid_cpy(&id, git_reference_target(ref)); git_reference_free(ref); /* Create it */ cl_git_pass(git_reference_create(&ref, g_repo, ref_name, &id, 0)); git_reference_free(ref); cl_git_pass(git_reference_lookup(&ref, g_repo, ref_test_name)); cl_assert(git_reference_type(ref) & GIT_REF_OID); git_oid_cpy(&id, git_reference_target(ref)); git_reference_free(ref); /* Ensure we can't overwrite unless we force it */ cl_git_fail(git_reference_create(&ref, g_repo, ref_name, &id, 0)); cl_git_pass(git_reference_create(&ref, g_repo, ref_name, &id, 1)); git_reference_free(ref); /* Ensure it has been overwritten */ cl_git_pass(git_reference_lookup(&ref, g_repo, ref_name)); cl_assert(!git_oid_cmp(&id, git_reference_target(ref))); git_reference_free(ref); }
void test_refs_reflog_reflog__fails_gracefully_on_nonempty_reflog_dir(void) { git_reference *ref; git_buf log_path = GIT_BUF_INIT; git_oid id; /* Create a new branch pointing at the HEAD */ git_oid_fromstr(&id, current_master_tip); cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/new-dir/new-head", &id, 0, NULL)); git_reference_free(ref); git_buf_joinpath(&log_path, git_repository_path(g_repo), GIT_REFLOG_DIR); git_buf_joinpath(&log_path, git_buf_cstr(&log_path), "refs/heads/new-dir/new-head"); cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&log_path))); /* delete the ref manually, leave the reflog */ cl_must_pass(p_unlink("testrepo.git/refs/heads/new-dir/new-head")); /* new ref creation should fail since new-dir contains reflogs still */ git_oid_fromstr(&id, current_master_tip); cl_git_fail_with(GIT_EDIRECTORY, git_reference_create(&ref, g_repo, "refs/heads/new-dir", &id, 0, NULL)); git_reference_free(ref); git_buf_dispose(&log_path); }
void test_refs_overwrite__symbolic_with_object_id(void) { // Overwrite an existing symbolic reference with an object id one git_reference *ref; git_oid id; cl_git_pass(git_reference_lookup(&ref, g_repo, ref_master_name)); cl_assert(git_reference_type(ref) & GIT_REF_OID); git_oid_cpy(&id, git_reference_target(ref)); git_reference_free(ref); /* Create the symbolic ref */ cl_git_pass(git_reference_symbolic_create(&ref, g_repo, ref_name, ref_master_name, 0)); git_reference_free(ref); /* It shouldn't overwrite unless we tell it to */ cl_git_fail(git_reference_create(&ref, g_repo, ref_name, &id, 0)); cl_git_pass(git_reference_create(&ref, g_repo, ref_name, &id, 1)); git_reference_free(ref); /* Ensure it points to the right place */ cl_git_pass(git_reference_lookup(&ref, g_repo, ref_name)); cl_assert(git_reference_type(ref) & GIT_REF_OID); cl_assert(!git_oid_cmp(git_reference_target(ref), &id)); git_reference_free(ref); }
void test_refs_rename__overwrite(void) { // can not overwrite name of existing reference git_reference *ref, *ref_one, *ref_one_new, *ref_two; git_refdb *refdb; git_oid id; cl_git_pass(git_reference_lookup(&ref, g_repo, ref_master_name)); cl_assert(git_reference_type(ref) & GIT_REF_OID); git_oid_cpy(&id, git_reference_target(ref)); /* Create loose references */ cl_git_pass(git_reference_create(&ref_one, g_repo, ref_one_name, &id, 0, NULL)); cl_git_pass(git_reference_create(&ref_two, g_repo, ref_two_name, &id, 0, NULL)); /* Pack everything */ cl_git_pass(git_repository_refdb(&refdb, g_repo)); cl_git_pass(git_refdb_compress(refdb)); /* Attempt to create illegal reference */ cl_git_fail(git_reference_create(&ref_one_new, g_repo, ref_one_name_new, &id, 0, NULL)); /* Illegal reference couldn't be created so this is supposed to fail */ cl_git_fail(git_reference_lookup(&ref_one_new, g_repo, ref_one_name_new)); git_reference_free(ref); git_reference_free(ref_one); git_reference_free(ref_one_new); git_reference_free(ref_two); git_refdb_free(refdb); }
void test_refs_reflog_reflog__removes_empty_reflog_dir(void) { git_reference *ref; git_buf log_path = GIT_BUF_INIT; git_oid id; /* Create a new branch pointing at the HEAD */ git_oid_fromstr(&id, current_master_tip); cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/new-dir/new-head", &id, 0, NULL)); git_buf_joinpath(&log_path, git_repository_path(g_repo), GIT_REFLOG_DIR); git_buf_joinpath(&log_path, git_buf_cstr(&log_path), "refs/heads/new-dir/new-head"); cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&log_path))); cl_git_pass(git_reference_delete(ref)); git_reference_free(ref); /* new ref creation should succeed since new-dir is empty */ git_oid_fromstr(&id, current_master_tip); cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/new-dir", &id, 0, NULL)); git_reference_free(ref); git_buf_dispose(&log_path); }
static int update_reflog( git_oid *w_commit_oid, git_repository *repo, const git_signature *stasher, const char *message) { git_reference *stash = NULL; git_reflog *reflog = NULL; int error; if ((error = git_reference_create(&stash, repo, GIT_REFS_STASH_FILE, w_commit_oid, 1)) < 0) goto cleanup; if ((error = git_reflog_read(&reflog, stash)) < 0) goto cleanup; if ((error = git_reflog_append(reflog, w_commit_oid, stasher, message)) < 0) goto cleanup; if ((error = git_reflog_write(reflog)) < 0) goto cleanup; cleanup: git_reference_free(stash); git_reflog_free(reflog); return error; }
static void commit_and_tag( git_time_t *time, const char *commit_msg, const char *tag_name) { git_index *index; git_oid commit_id; git_reference *ref; cl_git_pass(git_repository_index__weakptr(&index, repo)); cl_git_append2file("describe/file", "\n"); cl_git_pass(git_index_add_bypath(index, "file")); cl_git_pass(git_index_write(index)); *time += 10; cl_repo_commit_from_index(&commit_id, repo, NULL, *time, commit_msg); if (tag_name == NULL) return; cl_git_pass(git_reference_create(&ref, repo, tag_name, &commit_id, 0, NULL)); git_reference_free(ref); }
/* Can remove a note from a commit */ void test_notes_notes__can_remove_a_note_from_commit(void) { git_oid oid, notes_commit_oid; git_note *note = NULL; git_commit *existing_notes_commit; git_reference *ref; cl_git_pass(git_oid_fromstr(&oid, "4a202b346bb0fb0db7eff3cffeb3c70babbd2045")); cl_git_pass(git_note_commit_create(¬es_commit_oid, NULL, _repo, NULL, _sig, _sig, &oid, "I decorate 4a20\n", 0)); git_commit_lookup(&existing_notes_commit, _repo, ¬es_commit_oid); cl_assert(existing_notes_commit); cl_git_pass(git_note_commit_remove(¬es_commit_oid, _repo, existing_notes_commit, _sig, _sig, &oid)); /* remove_from_commit will not update any ref, * so we must manually create the ref, that points to the commit */ cl_git_pass(git_reference_create(&ref, _repo, "refs/notes/i-can-see-dead-notes", ¬es_commit_oid, 0, NULL)); cl_git_fail(git_note_read(¬e, _repo, "refs/notes/i-can-see-dead-notes", &oid)); git_commit_free(existing_notes_commit); git_reference_free(ref); git_note_free(note); }
/* Test that we can create a note from a commit, given an existing commit */ void test_notes_notes__can_create_a_note_from_commit_given_an_existing_commit(void) { git_oid oid; git_oid notes_commit_out; git_commit *existing_notes_commit = NULL; git_reference *ref; static struct note_create_payload can_create_a_note_from_commit_given_an_existing_commit[] = { { "1c9b1bc36730582a42d56eeee0dc58673d7ae869", "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", 0 }, { "1aaf94147c21f981e0a20bf57b89137c5a6aae52", "9fd738e8f7967c078dceed8190330fc8648ee56a", 0 }, { NULL, NULL, 0 } }; cl_git_pass(git_oid_fromstr(&oid, "4a202b346bb0fb0db7eff3cffeb3c70babbd2045")); cl_git_pass(git_note_commit_create(¬es_commit_out, NULL, _repo, NULL, _sig, _sig, &oid, "I decorate 4a20\n", 0)); cl_git_pass(git_oid_fromstr(&oid, "9fd738e8f7967c078dceed8190330fc8648ee56a")); git_commit_lookup(&existing_notes_commit, _repo, ¬es_commit_out); cl_assert(existing_notes_commit); cl_git_pass(git_note_commit_create(¬es_commit_out, NULL, _repo, existing_notes_commit, _sig, _sig, &oid, "I decorate 9fd7\n", 0)); /* create_from_commit will not update any ref, * so we must manually create the ref, that points to the commit */ cl_git_pass(git_reference_create(&ref, _repo, "refs/notes/i-can-see-dead-notes", ¬es_commit_out, 0, NULL)); cl_git_pass(git_note_foreach(_repo, "refs/notes/i-can-see-dead-notes", note_list_create_cb, &can_create_a_note_from_commit_given_an_existing_commit)); assert_notes_seen(can_create_a_note_from_commit_given_an_existing_commit, 2); git_commit_free(existing_notes_commit); git_reference_free(ref); }
void test_network_remote_defaultbranch__detached_sharing_nonbranch_id(void) { git_oid id, id_cloned; git_reference *ref; git_buf buf = GIT_BUF_INIT; git_repository *cloned_repo; cl_git_pass(git_reference_name_to_id(&id, g_repo_a, "HEAD")); cl_git_pass(git_repository_detach_head(g_repo_a, NULL, NULL)); cl_git_pass(git_reference_remove(g_repo_a, "refs/heads/master")); cl_git_pass(git_reference_remove(g_repo_a, "refs/heads/not-good")); cl_git_pass(git_reference_create(&ref, g_repo_a, "refs/foo/bar", &id, 1, NULL, NULL)); git_reference_free(ref); cl_git_pass(git_remote_connect(g_remote, GIT_DIRECTION_FETCH)); cl_git_fail_with(GIT_ENOTFOUND, git_remote_default_branch(&buf, g_remote)); cl_git_pass(git_clone(&cloned_repo, git_repository_path(g_repo_a), "./local-detached", NULL)); cl_assert(git_repository_head_detached(cloned_repo)); cl_git_pass(git_reference_name_to_id(&id_cloned, g_repo_a, "HEAD")); cl_assert(git_oid_equal(&id, &id_cloned)); git_repository_free(cloned_repo); }
static void assert_no_reflog_update(void) { size_t nlogs, nlogs_after; size_t nlogs_master, nlogs_master_after; git_reference *ref; git_reflog *log; git_oid id; cl_git_pass(git_reflog_read(&log, g_repo, "HEAD")); nlogs = git_reflog_entrycount(log); git_reflog_free(log); cl_git_pass(git_reflog_read(&log, g_repo, "refs/heads/master")); nlogs_master = git_reflog_entrycount(log); git_reflog_free(log); /* Move it back */ git_oid_fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"); cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/master", &id, 1, NULL)); git_reference_free(ref); cl_git_pass(git_reflog_read(&log, g_repo, "HEAD")); nlogs_after = git_reflog_entrycount(log); git_reflog_free(log); cl_assert_equal_i(nlogs_after, nlogs); cl_git_pass(git_reflog_read(&log, g_repo, "refs/heads/master")); nlogs_master_after = git_reflog_entrycount(log); git_reflog_free(log); cl_assert_equal_i(nlogs_after, nlogs); cl_assert_equal_i(nlogs_master_after, nlogs_master); }
void test_network_remote_rename__overwrite_ref_in_target(void) { git_oid id; char idstr[GIT_OID_HEXSZ + 1] = {0}; git_reference *ref; git_branch_t btype; git_branch_iterator *iter; git_strarray problems = {0}; cl_git_pass(git_oid_fromstr(&id, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750")); cl_git_pass(git_reference_create(&ref, _repo, "refs/remotes/renamed/master", &id, 1, NULL, NULL)); git_reference_free(ref); cl_git_pass(git_remote_rename(&problems, _repo, _remote_name, "renamed")); cl_assert_equal_i(0, problems.count); git_strarray_free(&problems); /* make sure there's only one remote-tracking branch */ cl_git_pass(git_branch_iterator_new(&iter, _repo, GIT_BRANCH_REMOTE)); cl_git_pass(git_branch_next(&ref, &btype, iter)); cl_assert_equal_s("refs/remotes/renamed/master", git_reference_name(ref)); git_oid_fmt(idstr, git_reference_target(ref)); cl_assert_equal_s("be3563ae3f795b2b4353bcce3a527ad0a4f7f644", idstr); git_reference_free(ref); cl_git_fail_with(GIT_ITEROVER, git_branch_next(&ref, &btype, iter)); git_branch_iterator_free(iter); }
int luagi_reference_create( lua_State *L ) { git_repository **repo = checkrepo( L, 1 ); const char *name = luaL_checkstring( L, 2 ); if( git_reference_is_valid_name( name ) == 0 ) { luaL_error( L, "invalid name" ); return 0; } git_oid oid; if( luagi_check_oid( &oid, L, 3 ) ) { ltk_error_abort( L ); } const char *log_message = luaL_checkstring( L, 5 ); int force = lua_toboolean( L, 6 ); git_reference **out = lua_newuserdata( L, sizeof( git_reference *) ); if( git_reference_create( out, *repo, name, &oid, force, log_message ) ) { return ltk_push_git_error( L ); } ltk_setmetatable( L, LUAGI_REFERENCE_FUNCS ); return 1; }
void test_refs_revparse__issue_994(void) { git_repository *repo; git_reference *head, *with_at; git_object *target; repo = cl_git_sandbox_init("testrepo.git"); cl_assert_equal_i(GIT_ENOTFOUND, git_revparse_single(&target, repo, "origin/bim_with_3d@11296")); cl_assert_equal_i(GIT_ENOTFOUND, git_revparse_single(&target, repo, "refs/remotes/origin/bim_with_3d@11296")); cl_git_pass(git_repository_head(&head, repo)); cl_git_pass(git_reference_create( &with_at, repo, "refs/remotes/origin/bim_with_3d@11296", git_reference_target(head), 0)); cl_git_pass(git_revparse_single(&target, repo, "origin/bim_with_3d@11296")); git_object_free(target); cl_git_pass(git_revparse_single(&target, repo, "refs/remotes/origin/bim_with_3d@11296")); git_object_free(target); git_reference_free(with_at); git_reference_free(head); cl_git_sandbox_cleanup(); }
void test_refs_reflog_reflog__append_then_read(void) { /* write a reflog for a given reference and ensure it can be read back */ git_reference *ref; git_oid oid; git_signature *committer; git_reflog *reflog; /* Create a new branch pointing at the HEAD */ git_oid_fromstr(&oid, current_master_tip); cl_git_pass(git_reference_create(&ref, g_repo, new_ref, &oid, 0, NULL)); git_reference_free(ref); cl_git_pass(git_signature_now(&committer, "foo", "foo@bar")); cl_git_pass(git_reflog_read(&reflog, g_repo, new_ref)); cl_git_fail(git_reflog_append(reflog, &oid, committer, "no inner\nnewline")); cl_git_pass(git_reflog_append(reflog, &oid, committer, NULL)); cl_git_pass(git_reflog_append(reflog, &oid, committer, commit_msg "\n")); cl_git_pass(git_reflog_write(reflog)); git_reflog_free(reflog); assert_appends(committer, &oid); git_signature_free(committer); }
static void *create_refs(void *arg) { int *id = arg, i; git_oid head; char name[128]; git_reference *ref[10]; cl_git_pass(git_reference_name_to_id(&head, g_repo, "HEAD")); for (i = 0; i < 10; ++i) { p_snprintf(name, sizeof(name), "refs/heads/thread-%03d-%02d", *id, i); cl_git_pass(git_reference_create(&ref[i], g_repo, name, &head, 0, NULL)); if (i == 5) { git_refdb *refdb; cl_git_pass(git_repository_refdb(&refdb, g_repo)); cl_git_pass(git_refdb_compress(refdb)); git_refdb_free(refdb); } } for (i = 0; i < 10; ++i) git_reference_free(ref[i]); giterr_clear(); return arg; }
void test_refs_pack__symbolic(void) { /* create a packfile from loose refs skipping symbolic refs */ int i; git_oid head; git_reference *ref; char name[128]; cl_git_pass(git_reference_name_to_id(&head, g_repo, "HEAD")); /* make a bunch of references */ for (i = 0; i < 100; ++i) { snprintf(name, sizeof(name), "refs/heads/symbolic-%03d", i); cl_git_pass(git_reference_symbolic_create( &ref, g_repo, name, "refs/heads/master", 0, NULL, NULL)); git_reference_free(ref); snprintf(name, sizeof(name), "refs/heads/direct-%03d", i); cl_git_pass(git_reference_create(&ref, g_repo, name, &head, 0, NULL, NULL)); git_reference_free(ref); } packall(); }
void test_refs_delete__packed_only(void) { // can delete a just packed reference git_reference *ref; git_refdb *refdb; git_oid id; const char *new_ref = "refs/heads/new_ref"; git_oid_fromstr(&id, current_master_tip); /* Create and write the new object id reference */ cl_git_pass(git_reference_create(&ref, g_repo, new_ref, &id, 0)); git_reference_free(ref); /* Lookup the reference */ cl_git_pass(git_reference_lookup(&ref, g_repo, new_ref)); /* Ensure it's a loose reference */ cl_assert(reference_is_packed(ref) == 0); /* Pack all existing references */ cl_git_pass(git_repository_refdb(&refdb, g_repo)); cl_git_pass(git_refdb_compress(refdb)); /* Reload the reference from disk */ git_reference_free(ref); cl_git_pass(git_reference_lookup(&ref, g_repo, new_ref)); /* Ensure it's a packed reference */ cl_assert(reference_is_packed(ref) == 1); /* This should pass */ cl_git_pass(git_reference_delete(ref)); git_reference_free(ref); }
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_create__oid(void) { /* create a new OID reference */ git_reference *new_reference, *looked_up_ref; git_repository *repo2; git_oid id; const char *new_head = "refs/heads/new-head"; git_oid_fromstr(&id, current_master_tip); /* Create and write the new object id reference */ cl_git_pass(git_reference_create(&new_reference, g_repo, new_head, &id, 0, NULL)); /* Ensure the reference can be looked-up... */ cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, new_head)); cl_assert(git_reference_type(looked_up_ref) & GIT_REF_OID); cl_assert(reference_is_packed(looked_up_ref) == 0); cl_assert_equal_s(looked_up_ref->name, new_head); /* ...and that it points to the current master tip */ cl_assert_equal_oid(&id, git_reference_target(looked_up_ref)); git_reference_free(looked_up_ref); /* Similar test with a fresh new repository */ cl_git_pass(git_repository_open(&repo2, "testrepo")); cl_git_pass(git_reference_lookup(&looked_up_ref, repo2, new_head)); cl_assert_equal_oid(&id, git_reference_target(looked_up_ref)); git_repository_free(repo2); git_reference_free(new_reference); git_reference_free(looked_up_ref); }
void test_refs_create__existing_dir_propagates_edirectory(void) { git_reference *new_reference, *fail_reference; git_oid id; const char *dir_head = "refs/heads/new-dir/new-head", *fail_head = "refs/heads/new-dir"; git_oid_fromstr(&id, current_master_tip); /* Create and write the new object id reference */ cl_git_pass(git_reference_create(&new_reference, g_repo, dir_head, &id, 1, NULL)); cl_git_fail_with(GIT_EDIRECTORY, git_reference_create(&fail_reference, g_repo, fail_head, &id, false, NULL)); git_reference_free(new_reference); }
void test_refs_rename__prefix(void) { // can be renamed to a new name prefixed with the old name git_reference *ref, *ref_two, *looked_up_ref, *renamed_ref; git_oid id; cl_git_pass(git_reference_lookup(&ref, g_repo, ref_master_name)); cl_assert(git_reference_type(ref) & GIT_REF_OID); git_oid_cpy(&id, git_reference_target(ref)); /* Create loose references */ cl_git_pass(git_reference_create(&ref_two, g_repo, ref_two_name, &id, 0, NULL)); /* An existing reference... */ cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, ref_two_name)); /* Can be rename to a new name starting with the old name. */ cl_git_pass(git_reference_rename(&renamed_ref, looked_up_ref, ref_two_name_new, 0, NULL)); git_reference_free(looked_up_ref); git_reference_free(renamed_ref); /* Check we actually renamed it */ cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, ref_two_name_new)); cl_assert_equal_s(looked_up_ref->name, ref_two_name_new); git_reference_free(looked_up_ref); cl_git_fail(git_reference_lookup(&looked_up_ref, g_repo, ref_two_name)); git_reference_free(ref); git_reference_free(ref_two); git_reference_free(looked_up_ref); }
void test_refs_rename__move_up(void) { // can move a reference to a upper reference hierarchy git_reference *ref, *ref_two, *looked_up_ref, *renamed_ref; git_oid id; cl_git_pass(git_reference_lookup(&ref, g_repo, ref_master_name)); cl_assert(git_reference_type(ref) & GIT_REF_OID); git_oid_cpy(&id, git_reference_target(ref)); /* Create loose references */ cl_git_pass(git_reference_create(&ref_two, g_repo, ref_two_name_new, &id, 0, NULL)); git_reference_free(ref_two); /* An existing reference... */ cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, ref_two_name_new)); /* Can be renamed upward the reference tree. */ cl_git_pass(git_reference_rename(&renamed_ref, looked_up_ref, ref_two_name, 0, NULL)); git_reference_free(looked_up_ref); git_reference_free(renamed_ref); /* Check we actually renamed it */ cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, ref_two_name)); cl_assert_equal_s(looked_up_ref->name, ref_two_name); git_reference_free(looked_up_ref); cl_git_fail(git_reference_lookup(&looked_up_ref, g_repo, ref_two_name_new)); git_reference_free(ref); git_reference_free(looked_up_ref); }
int git_rebase_abort(git_rebase *rebase) { git_reference *orig_head_ref = NULL; git_commit *orig_head_commit = NULL; int error; assert(rebase); if (rebase->inmemory) return 0; error = rebase->head_detached ? git_reference_create(&orig_head_ref, rebase->repo, GIT_HEAD_FILE, &rebase->orig_head_id, 1, "rebase: aborting") : git_reference_symbolic_create( &orig_head_ref, rebase->repo, GIT_HEAD_FILE, rebase->orig_head_name, 1, "rebase: aborting"); if (error < 0) goto done; if ((error = git_commit_lookup( &orig_head_commit, rebase->repo, &rebase->orig_head_id)) < 0 || (error = git_reset(rebase->repo, (git_object *)orig_head_commit, GIT_RESET_HARD, &rebase->options.checkout_options)) < 0) goto done; error = rebase_cleanup(rebase); done: git_commit_free(orig_head_commit); git_reference_free(orig_head_ref); return error; }
int git_branch_create( git_reference **ref_out, git_repository *repository, const char *branch_name, const git_commit *commit, int force) { git_reference *branch = NULL; git_buf canonical_branch_name = GIT_BUF_INIT; int error = -1; assert(branch_name && commit && ref_out); assert(git_object_owner((const git_object *)commit) == repository); if (git_buf_joinpath(&canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name) < 0) goto cleanup; error = git_reference_create(&branch, repository, git_buf_cstr(&canonical_branch_name), git_commit_id(commit), force); if (!error) *ref_out = branch; cleanup: git_buf_free(&canonical_branch_name); return error; }
static int create_branch( git_reference **branch, git_repository *repo, const git_oid *target, const char *name, const char *log_message) { git_commit *head_obj = NULL; git_reference *branch_ref = NULL; git_buf refname = GIT_BUF_INIT; int error; /* Find the target commit */ if ((error = git_commit_lookup(&head_obj, repo, target)) < 0) return error; /* Create the new branch */ if ((error = git_buf_printf(&refname, GIT_REFS_HEADS_DIR "%s", name)) < 0) return error; error = git_reference_create(&branch_ref, repo, git_buf_cstr(&refname), target, 0, log_message); git_buf_dispose(&refname); git_commit_free(head_obj); if (!error) *branch = branch_ref; else git_reference_free(branch_ref); return error; }
int git_rebase_init( git_rebase **out, git_repository *repo, const git_annotated_commit *branch, const git_annotated_commit *upstream, const git_annotated_commit *onto, const git_signature *signature, const git_rebase_options *given_opts) { git_rebase *rebase = NULL; git_rebase_options opts; git_reference *head_ref = NULL; git_buf reflog = GIT_BUF_INIT; git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT; int error; assert(repo && branch && (upstream || onto)); *out = NULL; GITERR_CHECK_VERSION(given_opts, GIT_REBASE_OPTIONS_VERSION, "git_rebase_options"); if (!onto) onto = upstream; checkout_opts.checkout_strategy = GIT_CHECKOUT_FORCE; if ((error = rebase_normalize_opts(repo, &opts, given_opts)) < 0 || (error = git_repository__ensure_not_bare(repo, "rebase")) < 0 || (error = rebase_ensure_not_in_progress(repo)) < 0 || (error = rebase_ensure_not_dirty(repo)) < 0) return error; rebase = git__calloc(1, sizeof(git_rebase)); GITERR_CHECK_ALLOC(rebase); if ((error = rebase_init(rebase, repo, branch, upstream, onto, &opts)) < 0 || (error = rebase_setupfiles(rebase)) < 0 || (error = git_buf_printf(&reflog, "rebase: checkout %s", rebase_onto_name(onto))) < 0 || (error = git_reference_create(&head_ref, repo, GIT_HEAD_FILE, git_annotated_commit_id(onto), 1, signature, reflog.ptr)) < 0 || (error = git_checkout_head(repo, &checkout_opts)) < 0) goto done; *out = rebase; done: if (error < 0) { rebase_cleanup(rebase); git_rebase_free(rebase); } git_reference_free(head_ref); git_buf_free(&reflog); rebase_opts_free(&opts); return error; }
void test_refs_branches_delete__initialize(void) { git_oid id; repo = cl_git_sandbox_init("testrepo.git"); cl_git_pass(git_oid_fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644")); cl_git_pass(git_reference_create(&fake_remote, repo, "refs/remotes/nulltoken/master", &id, 0, NULL)); }
void test_refs_reflog_reflog__write_only_std_locations(void) { git_reference *ref; git_oid id; git_oid_fromstr(&id, current_master_tip); cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/foo", &id, 1, NULL)); git_reference_free(ref); cl_git_pass(git_reference_create(&ref, g_repo, "refs/tags/foo", &id, 1, NULL)); git_reference_free(ref); cl_git_pass(git_reference_create(&ref, g_repo, "refs/notes/foo", &id, 1, NULL)); git_reference_free(ref); assert_has_reflog(true, "refs/heads/foo"); assert_has_reflog(false, "refs/tags/foo"); assert_has_reflog(true, "refs/notes/foo"); }
void test_refs_foreachglob__initialize(void) { git_oid id; cl_fixture_sandbox("testrepo.git"); cl_git_pass(git_repository_open(&repo, "testrepo.git")); cl_git_pass(git_oid_fromstr(&id, "be3563ae3f795b2b4353bcce3a527ad0a4f7f644")); cl_git_pass(git_reference_create(&fake_remote, repo, "refs/remotes/nulltoken/master", &id, 0)); }