void test_stash_drop__dropping_an_entry_rewrites_reflog_history(void) { git_reference *stash; git_reflog *reflog; const git_reflog_entry *entry; git_oid oid; size_t count; push_three_states(); cl_git_pass(git_reference_lookup(&stash, repo, GIT_REFS_STASH_FILE)); cl_git_pass(git_reflog_read(&reflog, stash)); entry = git_reflog_entry_byindex(reflog, 1); git_oid_cpy(&oid, git_reflog_entry_id_old(entry)); count = git_reflog_entrycount(reflog); git_reflog_free(reflog); cl_git_pass(git_stash_drop(repo, 1)); cl_git_pass(git_reflog_read(&reflog, stash)); entry = git_reflog_entry_byindex(reflog, 0); cl_assert_equal_i(0, git_oid_cmp(&oid, git_reflog_entry_id_old(entry))); cl_assert_equal_sz(count - 1, git_reflog_entrycount(reflog)); git_reflog_free(reflog); git_reference_free(stash); }
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_repo_head__set_to_current_target(void) { git_signature *sig; const char *msg; 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_signature_now(&sig, "me", "*****@*****.**")); msg = "message 1"; cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked", sig, msg)); cl_git_pass(git_repository_set_head(repo, "refs/heads/haacked", sig, msg)); 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); git_signature_free(sig); }
void test_refs_reflog_drop__can_persist_deletion_on_disk(void) { cl_assert(entrycount > 2); cl_git_pass(git_reflog_drop(g_reflog, 0, 1)); cl_assert_equal_sz(entrycount - 1, git_reflog_entrycount(g_reflog)); cl_git_pass(git_reflog_write(g_reflog)); git_reflog_free(g_reflog); git_reflog_read(&g_reflog, g_repo, "HEAD"); cl_assert_equal_sz(entrycount - 1, git_reflog_entrycount(g_reflog)); }
/** * ggit_reflog_get_entry_count: * @reflog: a #GgitReflog. * * Gets the number of log entries in @reflog. * * Returns: the number of log entries. */ guint ggit_reflog_get_entry_count (GgitReflog *reflog) { g_return_val_if_fail (reflog != NULL, 0); return git_reflog_entrycount (reflog->reflog); }
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); }
/* * call-seq: * reference.log -> [reflog_entry, ...] * * Return an array with the log of all modifications to this reference * * Each +reflog_entry+ is a hash with the following keys: * * - +:id_old+: previous OID before the change * - +:id_new+: OID after the change * - +:committer+: author of the change * - +:message+: message for the change * * Example: * * reference.log #=> [ * # { * # :id_old => nil, * # :id_new => '9d09060c850defbc7711d08b57def0d14e742f4e', * # :committer => {:name => 'Vicent Marti', :email => {'*****@*****.**'}}, * # :message => 'created reference' * # }, ... ] */ static VALUE rb_git_reflog(VALUE self) { git_reflog *reflog; git_reference *ref; int error; VALUE rb_log; size_t i, ref_count; Data_Get_Struct(self, git_reference, ref); error = git_reflog_read(&reflog, git_reference_owner(ref), git_reference_name(ref)); rugged_exception_check(error); ref_count = git_reflog_entrycount(reflog); rb_log = rb_ary_new2(ref_count); for (i = 0; i < ref_count; ++i) { const git_reflog_entry *entry = git_reflog_entry_byindex(reflog, ref_count - i - 1); rb_ary_push(rb_log, reflog_entry_new(entry)); } git_reflog_free(reflog); return rb_log; }
void test_refs_reflog_drop__can_drop_an_entry(void) { cl_assert(entrycount > 4); cl_git_pass(git_reflog_drop(g_reflog, 2, 0)); cl_assert_equal_i(entrycount - 1, git_reflog_entrycount(g_reflog)); }
void test_network_remote_local__fetch(void) { char *refspec_strings[] = { "master:remotes/sloppy/master", }; git_strarray array = { refspec_strings, 1, }; git_reflog *log; const git_reflog_entry *entry; git_reference *ref; connect_to_local_repository(cl_fixture("testrepo.git")); cl_git_pass(git_remote_fetch(remote, &array, NULL, "UPDAAAAAATE!!")); cl_git_pass(git_reference_lookup(&ref, repo, "refs/remotes/sloppy/master")); git_reference_free(ref); cl_git_pass(git_reflog_read(&log, repo, "refs/remotes/sloppy/master")); cl_assert_equal_i(1, git_reflog_entrycount(log)); entry = git_reflog_entry_byindex(log, 0); cl_assert_equal_s("*****@*****.**", git_reflog_entry_committer(entry)->email); cl_assert_equal_s("UPDAAAAAATE!!", git_reflog_entry_message(entry)); git_reflog_free(log); }
void test_network_remote_local__fetch_default_reflog_message(void) { char *refspec_strings[] = { "master:remotes/sloppy/master", }; git_strarray array = { refspec_strings, 1, }; git_reflog *log; const git_reflog_entry *entry; char expected_reflog_msg[1024]; connect_to_local_repository(cl_fixture("testrepo.git")); cl_git_pass(git_remote_fetch(remote, &array, NULL, NULL)); cl_git_pass(git_reflog_read(&log, repo, "refs/remotes/sloppy/master")); cl_assert_equal_i(1, git_reflog_entrycount(log)); entry = git_reflog_entry_byindex(log, 0); cl_assert_equal_s("*****@*****.**", git_reflog_entry_committer(entry)->email); sprintf(expected_reflog_msg, "fetch %s", git_remote_url(remote)); cl_assert_equal_s(expected_reflog_msg, git_reflog_entry_message(entry)); git_reflog_free(log); }
void test_refs_reflog_drop__initialize(void) { g_repo = cl_git_sandbox_init("testrepo.git"); git_reflog_read(&g_reflog, g_repo, "HEAD"); entrycount = git_reflog_entrycount(g_reflog); }
void test_repo_head__branch_birth(void) { git_signature *sig; git_oid id; git_tree *tree; git_reference *ref; const char *msg; 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_signature_now(&sig, "me", "*****@*****.**")); cl_git_pass(git_repository_head(&ref, repo)); cl_git_pass(git_reference_peel((git_object **) &tree, ref, GIT_OBJ_TREE)); git_reference_free(ref); msg = "message 1"; cl_git_pass(git_repository_set_head(repo, "refs/heads/orphan", sig, msg)); 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, nentries_after); msg = "message 2"; cl_git_pass(git_commit_create(&id, repo, "HEAD", sig, sig, NULL, msg, tree, 0, NULL)); git_tree_free(tree); cl_git_pass(git_reflog_read(&log, repo, "refs/heads/orphan")); cl_assert_equal_i(1, git_reflog_entrycount(log)); git_reflog_free(log); 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); git_signature_free(sig); }
ERL_NIF_TERM geef_reflog_read(ErlNifEnv *env, int argc, const ERL_NIF_TERM argv[]) { git_reflog *reflog; geef_repository *repo; ErlNifBinary bin; int error; size_t count, i; ERL_NIF_TERM list; if (!enif_get_resource(env, argv[0], geef_repository_type, (void **) &repo)) return enif_make_badarg(env); if (!enif_inspect_iolist_as_binary(env, argv[1], &bin)) return enif_make_badarg(env); if (!geef_terminate_binary(&bin)) return geef_oom(env); if ((error = git_reflog_read(&reflog, repo->repo, (char *)bin.data)) < 0) return geef_error(env); count = git_reflog_entrycount(reflog); list = enif_make_list(env, 0); for (i = count; i > 0; i--) { ErlNifBinary id_old, id_new, message; ERL_NIF_TERM tentry, name, email, time, offset; const git_reflog_entry *entry; entry = git_reflog_entry_byindex(reflog, i-1); if (geef_oid_bin(&id_old, git_reflog_entry_id_old(entry))) goto on_oom; if (geef_oid_bin(&id_new, git_reflog_entry_id_new(entry))) goto on_oom; if (geef_signature_to_erl(&name, &email, &time, &offset, env, git_reflog_entry_committer(entry))) goto on_oom; if (geef_string_to_bin(&message, git_reflog_entry_message(entry))) goto on_oom; tentry = enif_make_tuple7(env, name, email, time, offset, enif_make_binary(env, &id_old), enif_make_binary(env, &id_new), enif_make_binary(env, &message)); list = enif_make_list_cell(env, tentry, list); } git_reflog_free(reflog); return enif_make_tuple2(env, atoms.ok, list); on_oom: git_reflog_free(reflog); return geef_oom(env); }
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); }
void test_refs_reflog_drop__can_persist_deletion_on_disk(void) { git_reference *ref; cl_assert(entrycount > 2); cl_git_pass(git_reference_lookup(&ref, g_repo, g_reflog->ref_name)); cl_git_pass(git_reflog_drop(g_reflog, entrycount - 1, 1)); cl_assert_equal_i(entrycount - 1, git_reflog_entrycount(g_reflog)); cl_git_pass(git_reflog_write(g_reflog)); git_reflog_free(g_reflog); git_reflog_read(&g_reflog, ref); git_reference_free(ref); cl_assert_equal_i(entrycount - 1, git_reflog_entrycount(g_reflog)); }
static size_t entrycount(git_repository *repo, const char *name) { git_reflog *log; size_t ret; cl_git_pass(git_reflog_read(&log, repo, name)); ret = git_reflog_entrycount(log); git_reflog_free(log); return ret; }
static int retrieve_oid_from_reflog(git_oid *oid, git_reference *ref, unsigned int identifier) { git_reflog *reflog; int error = -1; unsigned int numentries; const git_reflog_entry *entry; bool search_by_pos = (identifier <= 100000000); if (git_reflog_read(&reflog, ref) < 0) return -1; numentries = git_reflog_entrycount(reflog); if (search_by_pos) { if (numentries < identifier + 1) { giterr_set( GITERR_REFERENCE, "Reflog for '%s' has only %d entries, asked for %d", git_reference_name(ref), numentries, identifier); error = GIT_ENOTFOUND; goto cleanup; } entry = git_reflog_entry_byindex(reflog, identifier); git_oid_cpy(oid, git_reflog_entry_oidold(entry)); error = 0; goto cleanup; } else { int i; git_time commit_time; for (i = numentries - 1; i >= 0; i--) { entry = git_reflog_entry_byindex(reflog, i); commit_time = git_reflog_entry_committer(entry)->when; if (commit_time.time - identifier > 0) continue; git_oid_cpy(oid, git_reflog_entry_oidnew(entry)); error = 0; goto cleanup; } error = GIT_ENOTFOUND; } cleanup: git_reflog_free(reflog); return error; }
void test_refs_reflog_drop__can_drop_all_the_entries(void) { cl_assert(--entrycount > 0); do { cl_git_pass(git_reflog_drop(g_reflog, --entrycount, 1)); } while (entrycount > 0); cl_git_pass(git_reflog_drop(g_reflog, 0, 1)); cl_assert_equal_i(0, git_reflog_entrycount(g_reflog)); }
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_refs_reflog_drop__initialize(void) { git_reference *ref; g_repo = cl_git_sandbox_init("testrepo.git"); cl_git_pass(git_reference_lookup(&ref, g_repo, "HEAD")); git_reflog_read(&g_reflog, ref); entrycount = git_reflog_entrycount(g_reflog); git_reference_free(ref); }
static int retrieve_oid_from_reflog(git_oid *oid, git_reference *ref, size_t identifier) { git_reflog *reflog; int error = -1; size_t numentries; const git_reflog_entry *entry; bool search_by_pos = (identifier <= 100000000); if (git_reflog_read(&reflog, git_reference_owner(ref), git_reference_name(ref)) < 0) return -1; numentries = git_reflog_entrycount(reflog); if (search_by_pos) { if (numentries < identifier + 1) { giterr_set( GITERR_REFERENCE, "Reflog for '%s' has only %"PRIuZ" entries, asked for %"PRIuZ, git_reference_name(ref), numentries, identifier); error = GIT_ENOTFOUND; goto cleanup; } entry = git_reflog_entry_byindex(reflog, identifier); git_oid_cpy(oid, git_reflog_entry_id_new(entry)); error = 0; goto cleanup; } else { size_t i; git_time commit_time; for (i = 0; i < numentries; i++) { entry = git_reflog_entry_byindex(reflog, i); commit_time = git_reflog_entry_committer(entry)->when; if (commit_time.time > (git_time_t)identifier) continue; git_oid_cpy(oid, git_reflog_entry_id_new(entry)); error = 0; goto cleanup; } error = GIT_ENOTFOUND; } cleanup: git_reflog_free(reflog); return error; }
void test_refs_reflog_reflog__append_to_HEAD_when_changing_current_branch(void) { size_t nlogs, nlogs_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); /* 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 + 1); }
void test_refs_reflog_reflog__do_not_append_when_no_update(void) { size_t nlogs, nlogs_after; git_reference *ref, *ref2; git_reflog *log; cl_git_pass(git_reflog_read(&log, g_repo, "HEAD")); nlogs = git_reflog_entrycount(log); git_reflog_free(log); cl_git_pass(git_reference_lookup(&ref, g_repo, "refs/heads/master")); cl_git_pass(git_reference_create(&ref2, g_repo, "refs/heads/master", git_reference_target(ref), 1, NULL)); git_reference_free(ref); git_reference_free(ref2); 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); }
static void check_last_reflog_entry(const char *email, const char *message) { git_reflog *log; const git_reflog_entry *entry; cl_git_pass(git_reflog_read(&log, repo, GIT_HEAD_FILE)); cl_assert(git_reflog_entrycount(log) > 0); entry = git_reflog_entry_byindex(log, 0); if (email) cl_assert_equal_s(email, git_reflog_entry_committer(entry)->email); if (message) cl_assert_equal_s(message, git_reflog_entry_message(entry)); git_reflog_free(log); }
/** * List the reflog within a specified reference. * * @param repo S4 class git_repository * @param ref Reference to read from. * @return VECXSP with S4 objects of class git_reflog */ SEXP git2r_reflog_list(SEXP repo, SEXP ref) { int err; size_t i, n; SEXP result = R_NilValue; git_reflog *reflog = NULL; git_repository *repository = NULL; if (git2r_arg_check_string(ref)) git2r_error(__func__, NULL, "'ref'", git2r_err_string_arg); repository = git2r_repository_open(repo); if (!repository) git2r_error(__func__, NULL, git2r_err_invalid_repository, NULL); err = git_reflog_read(&reflog, repository, CHAR(STRING_ELT(ref, 0))); if (err) goto cleanup; n = git_reflog_entrycount(reflog); PROTECT(result = allocVector(VECSXP, n)); for (i = 0; i < n; i++) { const git_reflog_entry *entry = git_reflog_entry_byindex(reflog, i); if (entry) { SEXP item; SET_VECTOR_ELT(result, i, item = NEW_OBJECT(MAKE_CLASS("git_reflog_entry"))); git2r_reflog_entry_init(entry, i, repo, ref, item); } } cleanup: if (reflog) git_reflog_free(reflog); if (repository) git_repository_free(repository); if (R_NilValue != result) UNPROTECT(1); if (err) git2r_error(__func__, giterr_last(), NULL, NULL); return result; }
PyObject * Reference_log(Reference *self) { RefLogIter *iter; CHECK_REFERENCE(self); iter = PyObject_New(RefLogIter, &RefLogIterType); if (iter != NULL) { git_reflog_read(&iter->reflog, self->reference); iter->size = git_reflog_entrycount(iter->reflog); iter->i = 0; } return (PyObject*)iter; }
static void assert_correct_reflog(const char *name) { git_reflog *log; const git_reflog_entry *entry; char expected_log_message[128] = {0}; sprintf(expected_log_message, "clone: from %s", cl_git_fixture_url("testrepo.git")); cl_git_pass(git_reflog_read(&log, g_repo, name)); cl_assert_equal_i(1, git_reflog_entrycount(log)); entry = git_reflog_entry_byindex(log, 0); cl_assert_equal_s(expected_log_message, git_reflog_entry_message(entry)); git_reflog_free(log); }
void test_refs_branches_delete__removes_reflog(void) { git_reference *branch; git_reflog *log; git_oid oidzero = {{0}}; git_signature *sig; /* Ensure the reflog has at least one entry */ cl_git_pass(git_signature_now(&sig, "Me", "*****@*****.**")); cl_git_pass(git_reflog_read(&log, repo, "refs/heads/track-local")); cl_git_pass(git_reflog_append(log, &oidzero, sig, "message")); cl_assert(git_reflog_entrycount(log) > 0); git_signature_free(sig); git_reflog_free(log); cl_git_pass(git_branch_lookup(&branch, repo, "track-local", GIT_BRANCH_LOCAL)); cl_git_pass(git_branch_delete(branch)); git_reference_free(branch); /* Reading a nonexistant reflog creates it, but it should be empty */ cl_git_pass(git_reflog_read(&log, repo, "refs/heads/track-local")); cl_assert_equal_i(0, git_reflog_entrycount(log)); git_reflog_free(log); }
void test_refs_reflog_reflog__reading_the_reflog_from_a_reference_with_no_log_returns_an_empty_one(void) { git_reflog *reflog; const char *refname = "refs/heads/subtrees"; git_buf subtrees_log_path = GIT_BUF_INIT; git_buf_join_n(&subtrees_log_path, '/', 3, git_repository_path(g_repo), GIT_REFLOG_DIR, refname); cl_assert_equal_i(false, git_path_isfile(git_buf_cstr(&subtrees_log_path))); cl_git_pass(git_reflog_read(&reflog, g_repo, refname)); cl_assert_equal_i(0, (int)git_reflog_entrycount(reflog)); git_reflog_free(reflog); git_buf_dispose(&subtrees_log_path); }