void test_network_fetchlocal__prune(void) { git_repository *repo; git_remote *origin; int callcount = 0; git_strarray refnames = {0}; git_reference *ref; git_repository *remote_repo = cl_git_sandbox_init("testrepo.git"); const char *url = cl_git_path_url(git_repository_path(remote_repo)); git_fetch_options options = GIT_FETCH_OPTIONS_INIT; options.callbacks.transfer_progress = transfer_cb; options.callbacks.payload = &callcount; cl_set_cleanup(&cleanup_local_repo, "foo"); cl_git_pass(git_repository_init(&repo, "foo", true)); cl_git_pass(git_remote_create(&origin, repo, GIT_REMOTE_ORIGIN, url)); cl_git_pass(git_remote_fetch(origin, NULL, &options, NULL)); cl_git_pass(git_reference_list(&refnames, repo)); cl_assert_equal_i(19, (int)refnames.count); cl_assert(callcount > 0); git_strarray_free(&refnames); git_remote_free(origin); cl_git_pass(git_reference_lookup(&ref, remote_repo, "refs/heads/br2")); cl_git_pass(git_reference_delete(ref)); git_reference_free(ref); cl_git_pass(git_remote_lookup(&origin, repo, GIT_REMOTE_ORIGIN)); cl_git_pass(git_remote_fetch(origin, NULL, &options, NULL)); cl_git_pass(git_remote_prune(origin, &options.callbacks)); cl_git_pass(git_reference_list(&refnames, repo)); cl_assert_equal_i(18, (int)refnames.count); git_strarray_free(&refnames); git_remote_free(origin); cl_git_pass(git_reference_lookup(&ref, remote_repo, "refs/heads/packed")); cl_git_pass(git_reference_delete(ref)); git_reference_free(ref); cl_git_pass(git_remote_lookup(&origin, repo, GIT_REMOTE_ORIGIN)); cl_git_pass(git_remote_fetch(origin, NULL, &options, NULL)); cl_git_pass(git_remote_prune(origin, &options.callbacks)); cl_git_pass(git_reference_list(&refnames, repo)); cl_assert_equal_i(17, (int)refnames.count); git_strarray_free(&refnames); git_remote_free(origin); git_repository_free(repo); }
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 void *delete_refs(void *arg) { int *id = arg, i; git_reference *ref; char name[128]; for (i = 0; i < 10; ++i) { p_snprintf( name, sizeof(name), "refs/heads/thread-%03d-%02d", (*id) & ~0x3, i); if (!git_reference_lookup(&ref, g_repo, name)) { cl_git_pass(git_reference_delete(ref)); git_reference_free(ref); } 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); } } giterr_clear(); return arg; }
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); }
int git_branch_delete(git_repository *repo, const char *branch_name, git_branch_t branch_type) { git_reference *branch = NULL; git_reference *head = NULL; int error; assert((branch_type == GIT_BRANCH_LOCAL) || (branch_type == GIT_BRANCH_REMOTE)); if ((error = retrieve_branch_reference(&branch, repo, branch_name, branch_type == GIT_BRANCH_REMOTE)) < 0) return error; if (git_reference_lookup(&head, repo, GIT_HEAD_FILE) < 0) { giterr_set(GITERR_REFERENCE, "Cannot locate HEAD."); goto on_error; } if ((git_reference_type(head) == GIT_REF_SYMBOLIC) && (strcmp(git_reference_target(head), git_reference_name(branch)) == 0)) { giterr_set(GITERR_REFERENCE, "Cannot delete branch '%s' as it is the current HEAD of the repository.", branch_name); goto on_error; } if (git_reference_delete(branch) < 0) goto on_error; git_reference_free(head); return 0; on_error: git_reference_free(head); git_reference_free(branch); return -1; }
void test_refs_delete__packed_loose(void) { // deleting a ref which is both packed and loose should remove both tracks in the filesystem git_reference *looked_up_ref, *another_looked_up_ref; git_buf temp_path = GIT_BUF_INIT; /* Ensure the loose reference exists on the file system */ cl_git_pass(git_buf_joinpath(&temp_path, g_repo->path_repository, packed_test_head_name)); cl_assert(git_path_exists(temp_path.ptr)); /* Lookup the reference */ cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, packed_test_head_name)); /* Ensure it's the loose version that has been found */ cl_assert(reference_is_packed(looked_up_ref) == 0); /* Now that the reference is deleted... */ cl_git_pass(git_reference_delete(looked_up_ref)); git_reference_free(looked_up_ref); /* Looking up the reference once again should not retrieve it */ cl_git_fail(git_reference_lookup(&another_looked_up_ref, g_repo, packed_test_head_name)); /* Ensure the loose reference doesn't exist any longer on the file system */ cl_assert(!git_path_exists(temp_path.ptr)); git_reference_free(another_looked_up_ref); git_buf_free(&temp_path); }
int luagi_reference_gen_delete( lua_State *L, const char *tablename ) { git_reference **ref = luaL_checkudata( L, 1, tablename ); if( git_reference_delete( *ref ) ) { ltk_error_abort( L ); } return 0; }
static int delete_cb(git_reference *ref, void *payload) { GIT_UNUSED(payload); cl_git_pass(git_reference_delete(ref)); git_reference_free(ref); return 0; }
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_refs_branches_delete__can_delete_a_branch_even_if_HEAD_is_missing(void) { git_reference *head; git_reference *branch; cl_git_pass(git_reference_lookup(&head, repo, GIT_HEAD_FILE)); git_reference_delete(head); git_reference_free(head); cl_git_pass(git_branch_lookup(&branch, repo, "br2", GIT_BRANCH_LOCAL)); cl_git_pass(git_branch_delete(branch)); git_reference_free(branch); }
/** * ggit_ref_delete: * @ref: a #GgitRef. * @error: a #GError for error reporting, or %NULL. * * Deletes @ref. * * This method works for both direct and symbolic references. * * The reference will be immediately removed on disk and from * memory. The given reference pointer will no longer be valid. */ void ggit_ref_delete (GgitRef *ref, GError **error) { gint ret; g_return_if_fail (ref != NULL); g_return_if_fail (error == NULL || *error == NULL); ret = git_reference_delete (_ggit_native_get (ref)); if (ret != GIT_OK) { _ggit_error_set (error, ret); } }
int git_stash_drop( git_repository *repo, size_t index) { git_reference *stash; git_reflog *reflog = NULL; size_t max; int error; if ((error = git_reference_lookup(&stash, repo, GIT_REFS_STASH_FILE)) < 0) return error; if ((error = git_reflog_read(&reflog, stash)) < 0) goto cleanup; max = git_reflog_entrycount(reflog); if (index > max - 1) { error = GIT_ENOTFOUND; giterr_set(GITERR_STASH, "No stashed state at position %" PRIuZ, index); goto cleanup; } if ((error = git_reflog_drop(reflog, index, true)) < 0) goto cleanup; if ((error = git_reflog_write(reflog)) < 0) goto cleanup; if (max == 1) { error = git_reference_delete(stash); git_reference_free(stash); stash = NULL; } else if (index == 0) { const git_reflog_entry *entry; entry = git_reflog_entry_byindex(reflog, 0); git_reference_free(stash); error = git_reference_create(&stash, repo, GIT_REFS_STASH_FILE, &entry->oid_cur, 1); } cleanup: git_reference_free(stash); git_reflog_free(reflog); return error; }
PyObject * Reference_delete(Reference *self, PyObject *args) { int err; CHECK_REFERENCE(self); /* Delete the reference */ err = git_reference_delete(self->reference); if (err < 0) return Error_set(err); git_reference_free(self->reference); self->reference = NULL; /* Invalidate the pointer */ Py_RETURN_NONE; }
void test_refs_reflog_reflog__deleting_the_reference_deletes_the_reflog(void) { git_reference *master; git_buf master_log_path = GIT_BUF_INIT; git_buf_joinpath(&master_log_path, git_repository_path(g_repo), GIT_REFLOG_DIR); git_buf_joinpath(&master_log_path, git_buf_cstr(&master_log_path), "refs/heads/master"); cl_assert_equal_i(true, git_path_isfile(git_buf_cstr(&master_log_path))); cl_git_pass(git_reference_lookup(&master, g_repo, "refs/heads/master")); cl_git_pass(git_reference_delete(master)); git_reference_free(master); cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&master_log_path))); git_buf_dispose(&master_log_path); }
int git_tag_delete(git_repository *repo, const char *tag_name) { git_reference *tag_ref; git_buf ref_name = GIT_BUF_INIT; int error; error = retrieve_tag_reference(&tag_ref, &ref_name, repo, tag_name); git_buf_free(&ref_name); if (error < 0) return error; if ((error = git_reference_delete(tag_ref)) == 0) git_reference_free(tag_ref); return error; }
void test_refs_crashes__double_free(void) { git_repository *repo; git_reference *ref, *ref2; const char *REFNAME = "refs/heads/xxx"; cl_git_pass(git_repository_open(&repo, cl_fixture("testrepo.git"))); cl_git_pass(git_reference_symbolic_create(&ref, repo, REFNAME, "refs/heads/master", 0)); cl_git_pass(git_reference_lookup(&ref2, repo, REFNAME)); cl_git_pass(git_reference_delete(ref)); git_reference_free(ref); git_reference_free(ref2); /* reference is gone from disk, so reloading it will fail */ cl_git_fail(git_reference_lookup(&ref2, repo, REFNAME)); git_repository_free(repo); }
void test_object_tag_write__basic(void) { // write a tag to the repository and read it again git_tag *tag; git_oid target_id, tag_id; git_signature *tagger; const git_signature *tagger1; git_reference *ref_tag; git_object *target; git_oid_fromstr(&target_id, tagged_commit); cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJ_COMMIT)); /* create signature */ cl_git_pass(git_signature_new(&tagger, tagger_name, tagger_email, 123456789, 60)); cl_git_pass( git_tag_create(&tag_id, g_repo, "the-tag", target, tagger, tagger_message, 0) ); git_object_free(target); git_signature_free(tagger); cl_git_pass(git_tag_lookup(&tag, g_repo, &tag_id)); cl_assert(git_oid_cmp(git_tag_target_oid(tag), &target_id) == 0); /* Check attributes were set correctly */ tagger1 = git_tag_tagger(tag); cl_assert(tagger1 != NULL); cl_assert_equal_s(tagger1->name, tagger_name); cl_assert_equal_s(tagger1->email, tagger_email); cl_assert(tagger1->when.time == 123456789); cl_assert(tagger1->when.offset == 60); cl_assert_equal_s(git_tag_message(tag), tagger_message); cl_git_pass(git_reference_lookup(&ref_tag, g_repo, "refs/tags/the-tag")); cl_assert(git_oid_cmp(git_reference_oid(ref_tag), &tag_id) == 0); cl_git_pass(git_reference_delete(ref_tag)); git_tag_free(tag); }
int git_branch_delete(git_reference *branch) { int is_head; git_buf config_section = GIT_BUF_INIT; int error = -1; assert(branch); if (!git_reference_is_branch(branch) && !git_reference_is_remote(branch)) { giterr_set(GITERR_INVALID, "Reference '%s' is not a valid branch.", git_reference_name(branch)); return -1; } if ((is_head = git_branch_is_head(branch)) < 0) return is_head; if (is_head) { giterr_set(GITERR_REFERENCE, "Cannot delete branch '%s' as it is the current HEAD of the repository.", git_reference_name(branch)); return -1; } if (git_buf_printf(&config_section, "branch.%s", git_reference_name(branch) + strlen(GIT_REFS_HEADS_DIR)) < 0) goto on_error; if (git_config_rename_section( git_reference_owner(branch), git_buf_cstr(&config_section), NULL) < 0) goto on_error; if (git_reference_delete(branch) < 0) goto on_error; error = 0; on_error: git_buf_free(&config_section); return error; }
static void *delete_refs(void *arg) { int i, error; struct th_data *data = (struct th_data *) arg; git_reference *ref; char name[128]; git_repository *repo; cl_git_thread_pass(data, git_repository_open(&repo, data->path)); for (i = 0; i < NREFS; ++i) { p_snprintf( name, sizeof(name), "refs/heads/thread-%03d-%02d", (data->id) & ~0x3, i); if (!git_reference_lookup(&ref, repo, name)) { do { error = git_reference_delete(ref); } while (error == GIT_ELOCKED); /* Sometimes we race with other deleter threads */ if (error == GIT_ENOTFOUND) error = 0; cl_git_thread_pass(data, error); git_reference_free(ref); } if (concurrent_compress && i == NREFS/2) { git_refdb *refdb; cl_git_thread_pass(data, git_repository_refdb(&refdb, repo)); do { error = git_refdb_compress(refdb); } while (error == GIT_ELOCKED); cl_git_thread_pass(data, error); git_refdb_free(refdb); } } git_repository_free(repo); git_error_clear(); return arg; }
void QGit::stashSave(QString name) { git_repository *repo = nullptr; git_reference *head = nullptr; //git_commit *commit = nullptr; git_signature *me = nullptr; //git_index *index = nullptr; git_oid *oid = nullptr; QStringList stashes; int res = 0; QGitError error; try { res = git_repository_open(&repo, m_path.absolutePath().toUtf8().constData()); if (res) { throw QGitError("git_repository_open", res); } res = git_signature_default(&me, repo); if (res) { throw QGitError("git_signature_default", res); } res = git_repository_head(&head, repo); if (res) { throw QGitError("git_repository_head", res); } // TODO: Check if we have memory leak here! oid = const_cast<git_oid *>(git_reference_target(head)); if (!oid) { throw QGitError("git_reference_target returned NULL", 0); } res = git_stash_save(oid, repo, me, name.toUtf8().constData(), 0); if (res) { throw QGitError("git_stash_save", res); } } catch(const QGitError &ex) { error = ex; } emit stashSaveReply(error); if (oid) { // TODO: Check if we need to free memory here! //git_oid_shorten_free(); oid = nullptr; } if (head) { git_reference_delete(head); head = nullptr; } if (me) { git_signature_free(me); me = nullptr; } if (repo) { git_repository_free(repo); repo = nullptr; } }