// write a new commit object from memory to disk void test_commit_write__from_memory(void) { git_oid tree_id, parent_id, commit_id; git_signature *author, *committer; const git_signature *author1, *committer1; git_commit *parent; git_tree *tree; const char *commit_id_str = "8496071c1b46c854b31185ea97743be6a8774479"; git_oid_fromstr(&tree_id, tree_oid); cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id)); git_oid_fromstr(&parent_id, commit_id_str); cl_git_pass(git_commit_lookup(&parent, g_repo, &parent_id)); /* create signatures */ cl_git_pass(git_signature_new(&committer, committer_name, committer_email, 123456789, 60)); cl_git_pass(git_signature_new(&author, committer_name, committer_email, 987654321, 90)); cl_git_pass(git_commit_create_v( &commit_id, /* out id */ g_repo, NULL, /* do not update the HEAD */ author, committer, NULL, commit_message, tree, 1, parent)); git_object_free((git_object *)parent); git_object_free((git_object *)tree); git_signature_free(committer); git_signature_free(author); cl_git_pass(git_commit_lookup(&commit, g_repo, &commit_id)); /* Check attributes were set correctly */ author1 = git_commit_author(commit); cl_assert(author1 != NULL); cl_assert_equal_s(committer_name, author1->name); cl_assert_equal_s(committer_email, author1->email); cl_assert(author1->when.time == 987654321); cl_assert(author1->when.offset == 90); committer1 = git_commit_committer(commit); cl_assert(committer1 != NULL); cl_assert_equal_s(committer_name, committer1->name); cl_assert_equal_s(committer_email, committer1->email); cl_assert(committer1->when.time == 123456789); cl_assert(committer1->when.offset == 60); cl_assert_equal_s(commit_message, git_commit_message(commit)); }
// create a root commit void test_commit_write__root(void) { git_oid tree_id, commit_id; const git_oid *branch_oid; git_signature *author, *committer; const char *branch_name = "refs/heads/root-commit-branch"; git_tree *tree; git_oid_fromstr(&tree_id, tree_oid); cl_git_pass(git_tree_lookup(&tree, g_repo, &tree_id)); /* create signatures */ cl_git_pass(git_signature_new(&committer, committer_name, committer_email, 123456789, 60)); cl_git_pass(git_signature_new(&author, committer_name, committer_email, 987654321, 90)); /* First we need to update HEAD so it points to our non-existant branch */ cl_git_pass(git_reference_lookup(&head, g_repo, "HEAD")); cl_assert(git_reference_type(head) == GIT_REF_SYMBOLIC); head_old = git__strdup(git_reference_symbolic_target(head)); cl_assert(head_old != NULL); git_reference_free(head); cl_git_pass(git_reference_symbolic_create(&head, g_repo, "HEAD", branch_name, 1)); cl_git_pass(git_commit_create_v( &commit_id, /* out id */ g_repo, "HEAD", author, committer, NULL, root_commit_message, tree, 0)); git_object_free((git_object *)tree); git_signature_free(committer); git_signature_free(author); /* * The fact that creating a commit works has already been * tested. Here we just make sure it's our commit and that it was * written as a root commit. */ cl_git_pass(git_commit_lookup(&commit, g_repo, &commit_id)); cl_assert(git_commit_parentcount(commit) == 0); cl_git_pass(git_reference_lookup(&branch, g_repo, branch_name)); branch_oid = git_reference_target(branch); cl_git_pass(git_oid_cmp(branch_oid, &commit_id)); cl_assert_equal_s(root_commit_message, git_commit_message(commit)); }
// Fixture setup and teardown void test_rebase_inmemory__initialize(void) { repo = cl_git_sandbox_init("rebase"); cl_git_pass(git_signature_new(&signature, "Rebaser", "*****@*****.**", 1405694510, 0)); }
void test_object_tag_write__overwrite(void) { // Attempt to write a tag bearing the same name than an already existing tag git_oid target_id, tag_id; git_signature *tagger; 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_assert_equal_i(GIT_EEXISTS, git_tag_create( &tag_id, /* out id */ g_repo, "e90810b", target, tagger, tagger_message, 0)); git_object_free(target); git_signature_free(tagger); }
git_signature *git_signature_now(const char *name, const char *email) { time_t now; time_t offset; struct tm *utc_tm, *local_tm; #ifndef GIT_WIN32 struct tm _utc, _local; #endif time(&now); /** * On Win32, `gmtime_r` doesn't exist but * `gmtime` is threadsafe, so we can use that */ #ifdef GIT_WIN32 utc_tm = gmtime(&now); local_tm = localtime(&now); #else utc_tm = gmtime_r(&now, &_utc); local_tm = localtime_r(&now, &_local); #endif offset = mktime(local_tm) - mktime(utc_tm); offset /= 60; /* mktime takes care of setting tm_isdst correctly */ if (local_tm->tm_isdst) offset += 60; return git_signature_new(name, email, now, (int)offset); }
git_signature *rugged_signature_get(VALUE rb_sig) { int error; VALUE rb_time, rb_unix_t, rb_offset, rb_name, rb_email; git_signature *sig; Check_Type(rb_sig, T_HASH); rb_name = rb_hash_aref(rb_sig, CSTR2SYM("name")); rb_email = rb_hash_aref(rb_sig, CSTR2SYM("email")); rb_time = rb_hash_aref(rb_sig, CSTR2SYM("time")); Check_Type(rb_name, T_STRING); Check_Type(rb_email, T_STRING); if (!rb_obj_is_kind_of(rb_time, rb_cTime)) rb_raise(rb_eTypeError, "expected Time object"); rb_unix_t = rb_funcall(rb_time, rb_intern("tv_sec"), 0); rb_offset = rb_funcall(rb_time, rb_intern("utc_offset"), 0); error = git_signature_new(&sig, StringValueCStr(rb_name), StringValueCStr(rb_email), NUM2LONG(rb_unix_t), FIX2INT(rb_offset) / 60); rugged_exception_check(error); return sig; }
int git_signature_now(git_signature **sig_out, const char *name, const char *email) { time_t now; time_t offset; struct tm *utc_tm; git_signature *sig; struct tm _utc; *sig_out = NULL; /* * Get the current time as seconds since the epoch and * transform that into a tm struct containing the time at * UTC. Give that to mktime which considers it a local time * (tm_isdst = -1 asks it to take DST into account) and gives * us that time as seconds since the epoch. The difference * between its return value and 'now' is our offset to UTC. */ time(&now); utc_tm = p_gmtime_r(&now, &_utc); utc_tm->tm_isdst = -1; offset = (time_t)difftime(now, mktime(utc_tm)); offset /= 60; if (git_signature_new(&sig, name, email, now, (int)offset) < 0) return -1; *sig_out = sig; return 0; }
void test_rebase_abort__merge(void) { git_rebase *rebase; git_reference *branch_ref, *onto_ref; git_signature *signature; git_annotated_commit *branch_head, *onto_head; cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef")); cl_git_pass(git_reference_lookup(&onto_ref, repo, "refs/heads/master")); cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref)); cl_git_pass(git_annotated_commit_from_ref(&onto_head, repo, onto_ref)); cl_git_pass(git_signature_new(&signature, "Rebaser", "*****@*****.**", 1404157834, -400)); cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, signature, NULL)); cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo)); test_abort(branch_head, onto_head); git_signature_free(signature); git_annotated_commit_free(branch_head); git_annotated_commit_free(onto_head); git_reference_free(branch_ref); git_reference_free(onto_ref); git_rebase_free(rebase); }
void test_rebase_abort__detached_head(void) { git_rebase *rebase; git_oid branch_id; git_reference *onto_ref; git_signature *signature; git_annotated_commit *branch_head, *onto_head; git_oid_fromstr(&branch_id, "b146bd7608eac53d9bf9e1a6963543588b555c64"); cl_git_pass(git_reference_lookup(&onto_ref, repo, "refs/heads/master")); cl_git_pass(git_annotated_commit_lookup(&branch_head, repo, &branch_id)); cl_git_pass(git_annotated_commit_from_ref(&onto_head, repo, onto_ref)); cl_git_pass(git_signature_new(&signature, "Rebaser", "*****@*****.**", 1404157834, -400)); cl_git_pass(git_rebase_init(&rebase, repo, branch_head, NULL, onto_head, signature, NULL)); cl_assert_equal_i(GIT_REPOSITORY_STATE_REBASE_MERGE, git_repository_state(repo)); test_abort(branch_head, onto_head); git_signature_free(signature); git_annotated_commit_free(branch_head); git_annotated_commit_free(onto_head); git_reference_free(onto_ref); git_rebase_free(rebase); }
void test_stash_save__initialize(void) { cl_git_pass(git_repository_init(&repo, "stash", 0)); cl_git_pass(git_signature_new(&signature, "nulltoken", "*****@*****.**", 1323847743, 60)); /* Wed Dec 14 08:29:03 2011 +0100 */ setup_stash(repo, signature); }
void test_commit_signature__create_zero_char(void) { // creating a zero character signature git_signature *sign; cl_git_fail(git_signature_new(&sign, "", "[email protected]", 1234567890, 60)); cl_assert(sign == NULL); }
static void stage_and_commit(git_repository *repo, const char *path) { git_oid tree_oid, commit_oid; git_tree *tree; git_signature *signature; git_index *index; cl_git_pass(git_repository_index(&index, repo)); cl_git_pass(git_index_add_bypath(index, path)); cl_git_pass(git_index_write(index)); cl_git_pass(git_index_write_tree(&tree_oid, index)); git_index_free(index); cl_git_pass(git_tree_lookup(&tree, repo, &tree_oid)); cl_git_pass(git_signature_new(&signature, "nulltoken", "*****@*****.**", 1323847743, 60)); cl_git_pass(git_commit_create_v( &commit_oid, repo, "HEAD", signature, signature, NULL, "Initial commit\n\0", tree, 0)); git_tree_free(tree); git_signature_free(signature); }
// Fixture setup and teardown void test_rebase_merge__initialize(void) { repo = cl_git_sandbox_init("rebase"); cl_git_pass(git_signature_new(&signature, "Rebaser", "*****@*****.**", 1405694510, 0)); set_core_autocrlf_to(repo, false); }
void test_rebase_merge__commit(void) { git_rebase *rebase; git_reference *branch_ref, *upstream_ref; git_annotated_commit *branch_head, *upstream_head; git_rebase_operation *rebase_operation; git_oid commit_id, tree_id, parent_id; git_signature *author; git_commit *commit; git_reflog *reflog; const git_reflog_entry *reflog_entry; cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/beef")); cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master")); cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref)); cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref)); cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL)); cl_git_pass(git_rebase_next(&rebase_operation, rebase)); cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature, NULL, NULL)); cl_git_pass(git_commit_lookup(&commit, repo, &commit_id)); git_oid_fromstr(&parent_id, "efad0b11c47cb2f0220cbd6f5b0f93bb99064b00"); cl_assert_equal_i(1, git_commit_parentcount(commit)); cl_assert_equal_oid(&parent_id, git_commit_parent_id(commit, 0)); git_oid_fromstr(&tree_id, "4461379789c777d2a6c1f2ee0e9d6c86731b9992"); cl_assert_equal_oid(&tree_id, git_commit_tree_id(commit)); cl_assert_equal_s(NULL, git_commit_message_encoding(commit)); cl_assert_equal_s("Modification 1 to beef\n", git_commit_message(commit)); cl_git_pass(git_signature_new(&author, "Edward Thomson", "*****@*****.**", 1405621769, 0-(4*60))); cl_assert(git_signature__equal(author, git_commit_author(commit))); cl_assert(git_signature__equal(signature, git_commit_committer(commit))); /* Make sure the reflogs are updated appropriately */ cl_git_pass(git_reflog_read(&reflog, repo, "HEAD")); cl_assert(reflog_entry = git_reflog_entry_byindex(reflog, 0)); cl_assert_equal_oid(&parent_id, git_reflog_entry_id_old(reflog_entry)); cl_assert_equal_oid(&commit_id, git_reflog_entry_id_new(reflog_entry)); cl_assert_equal_s("rebase: Modification 1 to beef", git_reflog_entry_message(reflog_entry)); git_reflog_free(reflog); git_signature_free(author); git_commit_free(commit); git_annotated_commit_free(branch_head); git_annotated_commit_free(upstream_head); git_reference_free(branch_ref); git_reference_free(upstream_ref); git_rebase_free(rebase); }
void test_stash_foreach__initialize(void) { cl_git_pass(git_signature_new( &signature, "nulltoken", "*****@*****.**", 1323847743, 60)); /* Wed Dec 14 08:29:03 2011 +0100 */ memset(&data, 0, sizeof(struct callback_data)); }
void cl_repo_commit_from_index( git_oid *out, git_repository *repo, git_signature *sig, git_time_t time, const char *msg) { git_index *index; git_oid commit_id, tree_id; git_object *parent = NULL; git_reference *ref = NULL; git_tree *tree = NULL; char buf[128]; int free_sig = (sig == NULL); /* it is fine if looking up HEAD fails - we make this the first commit */ git_revparse_ext(&parent, &ref, repo, "HEAD"); /* write the index content as a tree */ cl_git_pass(git_repository_index(&index, repo)); cl_git_pass(git_index_write_tree(&tree_id, index)); cl_git_pass(git_index_write(index)); git_index_free(index); cl_git_pass(git_tree_lookup(&tree, repo, &tree_id)); if (sig) cl_assert(sig->name && sig->email); else if (!time) cl_git_pass(git_signature_now(&sig, CL_COMMIT_NAME, CL_COMMIT_EMAIL)); else cl_git_pass(git_signature_new( &sig, CL_COMMIT_NAME, CL_COMMIT_EMAIL, time, 0)); if (!msg) { strcpy(buf, CL_COMMIT_MSG); git_oid_tostr(buf + strlen(CL_COMMIT_MSG), sizeof(buf) - strlen(CL_COMMIT_MSG), &tree_id); msg = buf; } cl_git_pass(git_commit_create_v( &commit_id, repo, ref ? git_reference_name(ref) : "HEAD", sig, sig, NULL, msg, tree, parent ? 1 : 0, parent)); if (out) git_oid_cpy(out, &commit_id); git_object_free(parent); git_reference_free(ref); if (free_sig) git_signature_free(sig); git_tree_free(tree); }
static int try_build_signature(const char *name, const char *email, git_time_t time, int offset) { git_signature *sign; int error = 0; if ((error = git_signature_new(&sign, name, email, time, offset)) < 0) return error; git_signature_free((git_signature *)sign); return error; }
git_signature *rugged_signature_get(VALUE rb_sig, git_repository *repo) { int error; VALUE rb_time, rb_unix_t, rb_offset, rb_name, rb_email, rb_time_offset; git_signature *sig; if (NIL_P(rb_sig)) { rugged_exception_check( git_signature_default(&sig, repo) ); return sig; } Check_Type(rb_sig, T_HASH); rb_name = rb_hash_aref(rb_sig, CSTR2SYM("name")); rb_email = rb_hash_aref(rb_sig, CSTR2SYM("email")); rb_time = rb_hash_aref(rb_sig, CSTR2SYM("time")); rb_time_offset = rb_hash_aref(rb_sig, CSTR2SYM("time_offset")); Check_Type(rb_name, T_STRING); Check_Type(rb_email, T_STRING); if (NIL_P(rb_time)) { error = git_signature_now(&sig, StringValueCStr(rb_name), StringValueCStr(rb_email)); } else { if (!rb_obj_is_kind_of(rb_time, rb_cTime)) rb_raise(rb_eTypeError, "expected Time object"); rb_unix_t = rb_funcall(rb_time, rb_intern("tv_sec"), 0); if (NIL_P(rb_time_offset)) { rb_offset = rb_funcall(rb_time, rb_intern("utc_offset"), 0); } else { Check_Type(rb_time_offset, T_FIXNUM); rb_offset = rb_time_offset; } error = git_signature_new(&sig, StringValueCStr(rb_name), StringValueCStr(rb_email), NUM2LONG(rb_unix_t), FIX2INT(rb_offset) / 60); } rugged_exception_check(error); return sig; }
static void assert_name_and_email( const char *expected_name, const char *expected_email, const char *name, const char *email) { git_signature *sign; cl_git_pass(git_signature_new(&sign, name, email, 1234567890, 60)); cl_assert_equal_s(expected_name, sign->name); cl_assert_equal_s(expected_email, sign->email); git_signature_free(sign); }
void test_stash_apply__initialize(void) { git_oid oid; repo = cl_git_sandbox_init_new("stash"); cl_git_pass(git_repository_index(&repo_index, repo)); cl_git_pass(git_signature_new(&signature, "nulltoken", "*****@*****.**", 1323847743, 60)); /* Wed Dec 14 08:29:03 2011 +0100 */ cl_git_mkfile("stash/what", "hello\n"); cl_git_mkfile("stash/how", "small\n"); cl_git_mkfile("stash/who", "world\n"); cl_git_mkfile("stash/where", "meh\n"); cl_git_pass(git_index_add_bypath(repo_index, "what")); cl_git_pass(git_index_add_bypath(repo_index, "how")); cl_git_pass(git_index_add_bypath(repo_index, "who")); cl_repo_commit_from_index(NULL, repo, signature, 0, "Initial commit"); cl_git_rewritefile("stash/what", "goodbye\n"); cl_git_rewritefile("stash/who", "funky world\n"); cl_git_mkfile("stash/when", "tomorrow\n"); cl_git_mkfile("stash/why", "would anybody use stash?\n"); cl_git_mkfile("stash/where", "????\n"); cl_git_pass(git_index_add_bypath(repo_index, "who")); cl_git_pass(git_index_add_bypath(repo_index, "why")); cl_git_pass(git_index_add_bypath(repo_index, "where")); git_index_write(repo_index); cl_git_rewritefile("stash/where", "....\n"); /* Pre-stash state */ assert_status(repo, "what", GIT_STATUS_WT_MODIFIED); assert_status(repo, "how", GIT_STATUS_CURRENT); assert_status(repo, "who", GIT_STATUS_INDEX_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|GIT_STATUS_WT_MODIFIED); cl_git_pass(git_stash_save(&oid, repo, signature, NULL, GIT_STASH_INCLUDE_UNTRACKED)); /* Post-stash state */ assert_status(repo, "what", GIT_STATUS_CURRENT); assert_status(repo, "how", GIT_STATUS_CURRENT); assert_status(repo, "who", GIT_STATUS_CURRENT); assert_status(repo, "when", GIT_ENOTFOUND); assert_status(repo, "why", GIT_ENOTFOUND); assert_status(repo, "where", GIT_ENOTFOUND); }
/* git reset --hard 72333f47d4e83616630ff3b0ffe4c0faebcc3c45 * git revert --no-commit d1d403d22cbe24592d725f442835cf46fe60c8ac */ void test_revert_workdir__again_after_automerge(void) { git_commit *head, *commit; git_tree *reverted_tree; git_oid head_oid, revert_oid, reverted_tree_oid, reverted_commit_oid; git_signature *signature; struct merge_index_entry merge_index_entries[] = { { 0100644, "caf99de3a49827117bb66721010eac461b06a80c", 0, "file1.txt" }, { 0100644, "0ab09ea6d4c3634bdf6c221626d8b6f7dd890767", 0, "file2.txt" }, { 0100644, "f4e107c230d08a60fb419d19869f1f282b272d9c", 0, "file3.txt" }, { 0100644, "0f5bfcf58c558d865da6be0281d7795993646cee", 0, "file6.txt" }, }; struct merge_index_entry second_revert_entries[] = { { 0100644, "3a3ef367eaf3fe79effbfb0a56b269c04c2b59fe", 1, "file1.txt" }, { 0100644, "caf99de3a49827117bb66721010eac461b06a80c", 2, "file1.txt" }, { 0100644, "747726e021bc5f44b86de60e3032fd6f9f1b8383", 3, "file1.txt" }, { 0100644, "0ab09ea6d4c3634bdf6c221626d8b6f7dd890767", 0, "file2.txt" }, { 0100644, "f4e107c230d08a60fb419d19869f1f282b272d9c", 0, "file3.txt" }, { 0100644, "0f5bfcf58c558d865da6be0281d7795993646cee", 0, "file6.txt" }, }; git_oid_fromstr(&head_oid, "72333f47d4e83616630ff3b0ffe4c0faebcc3c45"); cl_git_pass(git_commit_lookup(&head, repo, &head_oid)); cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL)); git_oid_fromstr(&revert_oid, "d1d403d22cbe24592d725f442835cf46fe60c8ac"); cl_git_pass(git_commit_lookup(&commit, repo, &revert_oid)); cl_git_pass(git_revert(repo, commit, NULL)); cl_assert(merge_test_index(repo_index, merge_index_entries, 4)); cl_git_pass(git_index_write_tree(&reverted_tree_oid, repo_index)); cl_git_pass(git_tree_lookup(&reverted_tree, repo, &reverted_tree_oid)); cl_git_pass(git_signature_new(&signature, "Reverter", "*****@*****.**", time(NULL), 0)); cl_git_pass(git_commit_create(&reverted_commit_oid, repo, "HEAD", signature, signature, NULL, "Reverted!", reverted_tree, 1, (const git_commit **)&head)); cl_git_pass(git_revert(repo, commit, NULL)); cl_assert(merge_test_index(repo_index, second_revert_entries, 6)); git_signature_free(signature); git_tree_free(reverted_tree); git_commit_free(commit); git_commit_free(head); }
int Signature_init(Signature *self, PyObject *args, PyObject *kwds) { char *keywords[] = {"name", "email", "time", "offset", "encoding", NULL}; PyObject *py_name, *tname; char *email, *encoding = "utf-8"; const char *name; long long time = -1; int offset = 0; int err; git_signature *signature; if (!PyArg_ParseTupleAndKeywords( args, kwds, "Os|Lis", keywords, &py_name, &email, &time, &offset, &encoding)) return -1; name = py_str_borrow_c_str(&tname, py_name, encoding); if (name == NULL) return -1; if (time == -1) { err = git_signature_now(&signature, name, email); } else { err = git_signature_new(&signature, name, email, time, offset); } Py_DECREF(tname); if (err < 0) { Error_set(err); return -1; } self->obj = NULL; self->signature = signature; if (encoding) { self->encoding = strdup(encoding); if (self->encoding == NULL) { PyErr_NoMemory(); return -1; } } return 0; }
static void test_abort(git_annotated_commit *branch, git_annotated_commit *onto) { git_rebase *rebase; git_reference *head_ref, *branch_ref = NULL; git_signature *signature; git_status_list *statuslist; git_reflog *reflog; const git_reflog_entry *reflog_entry; cl_git_pass(git_rebase_open(&rebase, repo)); cl_git_pass(git_signature_new(&signature, "Rebaser", "*****@*****.**", 1404157834, -400)); cl_git_pass(git_rebase_abort(rebase, signature)); cl_assert_equal_i(GIT_REPOSITORY_STATE_NONE, git_repository_state(repo)); /* Make sure the refs are updated appropriately */ cl_git_pass(git_reference_lookup(&head_ref, repo, "HEAD")); if (branch->ref_name == NULL) cl_assert_equal_oid(git_annotated_commit_id(branch), git_reference_target(head_ref)); else { cl_assert_equal_s("refs/heads/beef", git_reference_symbolic_target(head_ref)); cl_git_pass(git_reference_lookup(&branch_ref, repo, git_reference_symbolic_target(head_ref))); cl_assert_equal_oid(git_annotated_commit_id(branch), git_reference_target(branch_ref)); } git_status_list_new(&statuslist, repo, NULL); cl_assert_equal_i(0, git_status_list_entrycount(statuslist)); git_status_list_free(statuslist); /* Make sure the reflogs are updated appropriately */ cl_git_pass(git_reflog_read(&reflog, repo, "HEAD")); cl_assert(reflog_entry = git_reflog_entry_byindex(reflog, 0)); cl_assert_equal_oid(git_annotated_commit_id(onto), git_reflog_entry_id_old(reflog_entry)); cl_assert_equal_oid(git_annotated_commit_id(branch), git_reflog_entry_id_new(reflog_entry)); cl_assert_equal_s("rebase: aborting", git_reflog_entry_message(reflog_entry)); git_reflog_free(reflog); git_reference_free(head_ref); git_reference_free(branch_ref); git_signature_free(signature); git_rebase_free(rebase); }
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); }
/* * revert the same commit twice (when the first reverts cleanly): * * git revert 2d440f2 * git revert 2d440f2 */ void test_revert_workdir__again_after_edit(void) { git_reference *head_ref; git_commit *orig_head, *commit; git_tree *reverted_tree; git_oid orig_head_oid, revert_oid, reverted_tree_oid, reverted_commit_oid; git_signature *signature; struct merge_index_entry merge_index_entries[] = { { 0100644, "3721552e06c4bdc7d478e0674e6304888545d5fd", 0, "file1.txt" }, { 0100644, "0ab09ea6d4c3634bdf6c221626d8b6f7dd890767", 0, "file2.txt" }, { 0100644, "f4e107c230d08a60fb419d19869f1f282b272d9c", 0, "file3.txt" }, { 0100644, "0f5bfcf58c558d865da6be0281d7795993646cee", 0, "file6.txt" }, }; cl_git_pass(git_repository_head(&head_ref, repo)); cl_git_pass(git_oid_fromstr(&orig_head_oid, "399fb3aba3d9d13f7d40a9254ce4402067ef3149")); cl_git_pass(git_commit_lookup(&orig_head, repo, &orig_head_oid)); cl_git_pass(git_reset(repo, (git_object *)orig_head, GIT_RESET_HARD, NULL)); cl_git_pass(git_oid_fromstr(&revert_oid, "2d440f2b3147d3dc7ad1085813478d6d869d5a4d")); cl_git_pass(git_commit_lookup(&commit, repo, &revert_oid)); cl_git_pass(git_revert(repo, commit, NULL)); cl_assert(merge_test_index(repo_index, merge_index_entries, 4)); cl_git_pass(git_index_write_tree(&reverted_tree_oid, repo_index)); cl_git_pass(git_tree_lookup(&reverted_tree, repo, &reverted_tree_oid)); cl_git_pass(git_signature_new(&signature, "Reverter", "*****@*****.**", time(NULL), 0)); cl_git_pass(git_commit_create(&reverted_commit_oid, repo, "HEAD", signature, signature, NULL, "Reverted!", reverted_tree, 1, (const git_commit **)&orig_head)); cl_git_pass(git_revert(repo, commit, NULL)); cl_assert(merge_test_index(repo_index, merge_index_entries, 4)); git_signature_free(signature); git_tree_free(reverted_tree); git_commit_free(commit); git_commit_free(orig_head); git_reference_free(head_ref); }
// Fixture setup and teardown void test_rebase_submodule__initialize(void) { git_index *index; git_oid tree_oid, commit_id; git_tree *tree; git_commit *parent; git_object *obj; git_reference *master_ref; git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT; opts.checkout_strategy = GIT_CHECKOUT_FORCE; repo = cl_git_sandbox_init("rebase-submodule"); cl_git_pass(git_signature_new(&signature, "Rebaser", "*****@*****.**", 1405694510, 0)); rewrite_gitmodules(git_repository_workdir(repo)); cl_git_pass(git_submodule_set_url(repo, "my-submodule", git_repository_path(repo))); /* We have to commit the rewritten .gitmodules file */ cl_git_pass(git_repository_index(&index, repo)); cl_git_pass(git_index_add_bypath(index, ".gitmodules")); cl_git_pass(git_index_write_tree(&tree_oid, index)); cl_git_pass(git_tree_lookup(&tree, repo, &tree_oid)); cl_git_pass(git_repository_head(&master_ref, repo)); cl_git_pass(git_commit_lookup(&parent, repo, git_reference_target(master_ref))); cl_git_pass(git_commit_create_v(&commit_id, repo, git_reference_name(master_ref), signature, signature, NULL, "Fixup .gitmodules", tree, 1, parent)); /* And a final reset, for good measure */ cl_git_pass(git_object_lookup(&obj, repo, &commit_id, GIT_OBJ_COMMIT)); cl_git_pass(git_reset(repo, obj, GIT_RESET_HARD, &opts)); git_index_free(index); git_object_free(obj); git_commit_free(parent); git_reference_free(master_ref); git_tree_free(tree); }
/* git reset --hard cfc4f0999a8367568e049af4f72e452d40828a15 * git cherry-pick a43a050c588d4e92f11a6b139680923e9728477d*/ void test_cherrypick_workdir__empty_result(void) { git_oid head_oid; git_signature *signature = NULL; git_commit *head = NULL, *commit = NULL; git_oid cherry_oid; const char *cherrypick_oid = "a43a050c588d4e92f11a6b139680923e9728477d"; struct merge_index_entry merge_index_entries[] = { { 0100644, "19c5c7207054604b69c84d08a7571ef9672bb5c2", 0, "file1.txt" }, { 0100644, "a58ca3fee5eb68b11adc2703e5843f968c9dad1e", 0, "file2.txt" }, { 0100644, "28d9eb4208074ad1cc84e71ccc908b34573f05d2", 0, "file3.txt" }, }; cl_git_pass(git_signature_new(&signature, "Picker", "*****@*****.**", time(NULL), 0)); git_oid_fromstr(&head_oid, "cfc4f0999a8367568e049af4f72e452d40828a15"); /* Create an untracked file that should not conflict */ cl_git_mkfile(TEST_REPO_PATH "/file4.txt", ""); cl_assert(git_path_exists(TEST_REPO_PATH "/file4.txt")); cl_git_pass(git_commit_lookup(&head, repo, &head_oid)); cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL)); git_oid_fromstr(&cherry_oid, cherrypick_oid); cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid)); cl_git_pass(git_cherrypick(repo, commit, NULL)); /* The resulting tree should not have changed, the change was already on HEAD */ cl_assert(merge_test_index(repo_index, merge_index_entries, 3)); git_commit_free(head); git_commit_free(commit); git_signature_free(signature); }
void test_describe_t6120__pattern(void) { git_describe_options opts = GIT_DESCRIBE_OPTIONS_INIT; git_describe_format_options fmt_opts = GIT_DESCRIBE_FORMAT_OPTIONS_INIT; git_oid tag_id; git_object *head; git_signature *tagger; git_time_t time; /* set-up matching pattern tests */ cl_git_pass(git_revparse_single(&head, repo, "HEAD")); time = 1380553019; cl_git_pass(git_signature_new(&tagger, "tagger", "*****@*****.**", time, 0)); cl_git_pass(git_tag_create(&tag_id, repo, "test-annotated", head, tagger, "test-annotated", 0)); git_signature_free(tagger); git_object_free(head); commit_and_tag(&time, "one more", "refs/tags/test1-lightweight"); commit_and_tag(&time, "yet another", "refs/tags/test2-lightweight"); commit_and_tag(&time, "even more", NULL); /* Exercize */ opts.pattern = "test-*"; assert_describe("test-annotated-*", "HEAD", repo, &opts, &fmt_opts); opts.describe_strategy = GIT_DESCRIBE_TAGS; opts.pattern = "test1-*"; assert_describe("test1-lightweight-*", "HEAD", repo, &opts, &fmt_opts); opts.pattern = "test2-*"; assert_describe("test2-lightweight-*", "HEAD", repo, &opts, &fmt_opts); fmt_opts.always_use_long_format = 1; assert_describe("test2-lightweight-*", "HEAD^", repo, &opts, &fmt_opts); }
/* * revert the same commit twice (when the first reverts cleanly): * * git revert 2d440f2 * git revert 2d440f2 */ void test_revert_workdir__again(void) { git_reference *head_ref; git_commit *orig_head; git_tree *reverted_tree; git_oid reverted_tree_oid, reverted_commit_oid; git_signature *signature; struct merge_index_entry merge_index_entries[] = { { 0100644, "7731926a337c4eaba1e2187d90ebfa0a93659382", 0, "file1.txt" }, { 0100644, "0ab09ea6d4c3634bdf6c221626d8b6f7dd890767", 0, "file2.txt" }, { 0100644, "f4e107c230d08a60fb419d19869f1f282b272d9c", 0, "file3.txt" }, { 0100644, "0f5bfcf58c558d865da6be0281d7795993646cee", 0, "file6.txt" }, }; cl_git_pass(git_repository_head(&head_ref, repo)); cl_git_pass(git_reference_peel((git_object **)&orig_head, head_ref, GIT_OBJ_COMMIT)); cl_git_pass(git_reset(repo, (git_object *)orig_head, GIT_RESET_HARD, NULL)); cl_git_pass(git_revert(repo, orig_head, NULL)); cl_assert(merge_test_index(repo_index, merge_index_entries, 4)); cl_git_pass(git_index_write_tree(&reverted_tree_oid, repo_index)); cl_git_pass(git_tree_lookup(&reverted_tree, repo, &reverted_tree_oid)); cl_git_pass(git_signature_new(&signature, "Reverter", "*****@*****.**", time(NULL), 0)); cl_git_pass(git_commit_create(&reverted_commit_oid, repo, "HEAD", signature, signature, NULL, "Reverted!", reverted_tree, 1, (const git_commit **)&orig_head)); cl_git_pass(git_revert(repo, orig_head, NULL)); cl_assert(merge_test_index(repo_index, merge_index_entries, 4)); git_signature_free(signature); git_tree_free(reverted_tree); git_commit_free(orig_head); git_reference_free(head_ref); }
void test_object_tag_write__replace(void) { // Replace an already existing tag git_oid target_id, tag_id, old_tag_id; git_signature *tagger; 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)); cl_git_pass(git_reference_lookup(&ref_tag, g_repo, "refs/tags/e90810b")); git_oid_cpy(&old_tag_id, git_reference_oid(ref_tag)); git_reference_free(ref_tag); /* create signature */ cl_git_pass(git_signature_new(&tagger, tagger_name, tagger_email, 123456789, 60)); cl_git_pass(git_tag_create( &tag_id, /* out id */ g_repo, "e90810b", target, tagger, tagger_message, 1)); git_object_free(target); git_signature_free(tagger); cl_git_pass(git_reference_lookup(&ref_tag, g_repo, "refs/tags/e90810b")); cl_assert(git_oid_cmp(git_reference_oid(ref_tag), &tag_id) == 0); cl_assert(git_oid_cmp(git_reference_oid(ref_tag), &old_tag_id) != 0); git_reference_free(ref_tag); }