void test_refs_overwrite__symbolic(void) { // Overwrite an existing symbolic reference git_reference *ref, *branch_ref; /* The target needds to exist and we need to check the name has changed */ cl_git_pass(git_reference_symbolic_create(&branch_ref, g_repo, ref_branch_name, ref_master_name, 0)); cl_git_pass(git_reference_symbolic_create(&ref, g_repo, ref_name, ref_branch_name, 0)); 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_SYMBOLIC); cl_assert_equal_s(git_reference_symbolic_target(ref), ref_branch_name); git_reference_free(ref); /* Ensure we can't create it unless we force it to */ cl_git_fail(git_reference_symbolic_create(&ref, g_repo, ref_name, ref_master_name, 0)); cl_git_pass(git_reference_symbolic_create(&ref, g_repo, ref_name, ref_master_name, 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_SYMBOLIC); cl_assert_equal_s(git_reference_symbolic_target(ref), ref_master_name); git_reference_free(ref); git_reference_free(branch_ref); }
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); }
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; }
static int merge_trivial(const char *ours, const char *theirs, bool automerge) { git_buf branch_buf = GIT_BUF_INIT; git_checkout_opts checkout_opts = GIT_CHECKOUT_OPTS_INIT; git_reference *our_ref, *their_ref; git_merge_head *their_heads[1]; git_merge_opts opts = GIT_MERGE_OPTS_INIT; git_merge_result *result; checkout_opts.checkout_strategy = GIT_CHECKOUT_FORCE; opts.merge_tree_opts.automerge_flags |= automerge ? 0 : GIT_MERGE_AUTOMERGE_NONE; git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours); cl_git_pass(git_reference_symbolic_create(&our_ref, repo, "HEAD", branch_buf.ptr, 1)); cl_git_pass(git_checkout_head(repo, &checkout_opts)); git_buf_clear(&branch_buf); git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, theirs); cl_git_pass(git_reference_lookup(&their_ref, repo, branch_buf.ptr)); cl_git_pass(git_merge_head_from_ref(&their_heads[0], repo, their_ref)); cl_git_pass(git_merge(&result, repo, (const git_merge_head **)their_heads, 1, &opts)); git_buf_free(&branch_buf); git_reference_free(our_ref); git_reference_free(their_ref); git_merge_head_free(their_heads[0]); git_merge_result_free(result); return 0; }
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_reflog_messages__detaching_head_default_message(void) { git_reference *ref; cl_assert_equal_i(false, git_repository_head_detached(g_repo)); cl_git_pass(git_repository_detach_head(g_repo)); cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", NULL, "checkout: moving from master to a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); cl_assert_equal_i(true, git_repository_head_detached(g_repo)); /* take the repo back to its original state */ cl_git_pass(git_reference_symbolic_create(&ref, g_repo, "HEAD", "refs/heads/master", true, "REATTACH")); cl_reflog_check_entry(g_repo, GIT_HEAD_FILE, 0, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", NULL, "REATTACH"); cl_assert_equal_i(false, git_repository_head_detached(g_repo)); git_reference_free(ref); }
void test_refs_create__symbolic_with_arbitrary_content(void) { git_reference *new_reference, *looked_up_ref; git_repository *repo2; git_oid id; const char *new_head_tracker = "ANOTHER_HEAD_TRACKER"; const char *arbitrary_target = "ARBITRARY DATA"; git_oid_fromstr(&id, current_master_tip); /* Attempt to create symbolic ref with arbitrary data in target * fails by default */ cl_git_fail(git_reference_symbolic_create(&new_reference, g_repo, new_head_tracker, arbitrary_target, 0, NULL)); git_libgit2_opts(GIT_OPT_ENABLE_STRICT_SYMBOLIC_REF_CREATION, 0); /* With strict target validation disabled, ref creation succeeds */ cl_git_pass(git_reference_symbolic_create(&new_reference, g_repo, new_head_tracker, arbitrary_target, 0, NULL)); /* Ensure the reference can be looked-up... */ cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, new_head_tracker)); cl_assert(git_reference_type(looked_up_ref) & GIT_REF_SYMBOLIC); cl_assert(reference_is_packed(looked_up_ref) == 0); cl_assert_equal_s(looked_up_ref->name, new_head_tracker); git_reference_free(looked_up_ref); /* Ensure the target is what we expect it to be */ cl_assert_equal_s(git_reference_symbolic_target(new_reference), arbitrary_target); /* Similar test with a fresh new repository object */ cl_git_pass(git_repository_open(&repo2, "testrepo")); /* Ensure the reference can be looked-up... */ cl_git_pass(git_reference_lookup(&looked_up_ref, repo2, new_head_tracker)); cl_assert(git_reference_type(looked_up_ref) & GIT_REF_SYMBOLIC); cl_assert(reference_is_packed(looked_up_ref) == 0); cl_assert_equal_s(looked_up_ref->name, new_head_tracker); /* Ensure the target is what we expect it to be */ cl_assert_equal_s(git_reference_symbolic_target(new_reference), arbitrary_target); git_repository_free(repo2); git_reference_free(new_reference); git_reference_free(looked_up_ref); }
void assert_conflict( const char *entry_path, const char *new_content, const char *parent_sha, const char *commit_sha) { git_index *index; git_object *hack_tree; git_reference *branch, *head; git_buf file_path = GIT_BUF_INIT; cl_git_pass(git_repository_index(&index, g_repo)); /* Create a branch pointing at the parent */ cl_git_pass(git_revparse_single(&g_object, g_repo, parent_sha)); cl_git_pass(git_branch_create(&branch, g_repo, "potential_conflict", (git_commit *)g_object, 0)); /* Make HEAD point to this branch */ cl_git_pass(git_reference_symbolic_create( &head, g_repo, "HEAD", git_reference_name(branch), 1, NULL)); git_reference_free(head); git_reference_free(branch); /* Checkout the parent */ g_opts.checkout_strategy = GIT_CHECKOUT_FORCE; cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts)); /* Hack-ishy workaound to ensure *all* the index entries * match the content of the tree */ cl_git_pass(git_object_peel(&hack_tree, g_object, GIT_OBJ_TREE)); cl_git_pass(git_index_read_tree(index, (git_tree *)hack_tree)); git_object_free(hack_tree); git_object_free(g_object); g_object = NULL; /* Create a conflicting file */ cl_git_pass(git_buf_joinpath(&file_path, "./testrepo", entry_path)); cl_git_mkfile(git_buf_cstr(&file_path), new_content); git_buf_free(&file_path); /* Trying to checkout the original commit */ cl_git_pass(git_revparse_single(&g_object, g_repo, commit_sha)); g_opts.checkout_strategy = GIT_CHECKOUT_SAFE; cl_assert_equal_i( GIT_ECONFLICT, git_checkout_tree(g_repo, g_object, &g_opts)); /* Stage the conflicting change */ cl_git_pass(git_index_add_bypath(index, entry_path)); cl_git_pass(git_index_write(index)); git_index_free(index); cl_assert_equal_i( GIT_ECONFLICT, git_checkout_tree(g_repo, g_object, &g_opts)); }
void test_refs_update__updating_the_target_of_a_symref_with_an_invalid_name_returns_EINVALIDSPEC(void) { git_reference *head; cl_git_pass(git_reference_lookup(&head, g_repo, GIT_HEAD_FILE)); cl_assert_equal_i(GIT_REFERENCE_SYMBOLIC, git_reference_type(head)); git_reference_free(head); cl_assert_equal_i(GIT_EINVALIDSPEC, git_reference_symbolic_create(&head, g_repo, GIT_HEAD_FILE, "refs/heads/inv@{id", 1, NULL)); }
void test_repo_head__detach_head_Fails_if_HEAD_and_point_to_a_non_commitish(void) { git_reference *head; cl_git_pass(git_reference_symbolic_create(&head, repo, GIT_HEAD_FILE, "refs/tags/point_to_blob", 1, NULL)); cl_git_fail(git_repository_detach_head(repo)); git_reference_free(head); }
void test_submodule_lookup__lookup_even_with_unborn_head(void) { git_reference *head; /* put us on an unborn branch */ cl_git_pass(git_reference_symbolic_create( &head, g_repo, "HEAD", "refs/heads/garbage", 1, NULL, NULL)); git_reference_free(head); test_submodule_lookup__simple_lookup(); /* baseline should still pass */ }
void test_stash_save__cannot_stash_against_an_unborn_branch(void) { git_reference *head; cl_git_pass(git_reference_symbolic_create(&head, repo, "HEAD", "refs/heads/unborn", 1, NULL)); cl_assert_equal_i(GIT_EUNBORNBRANCH, git_stash_save(&stash_tip_oid, repo, signature, NULL, GIT_STASH_DEFAULT)); git_reference_free(head); }
static void test_invalid_name(const char *name) { git_reference *new_reference; git_oid id; git_oid_fromstr(&id, current_master_tip); cl_assert_equal_i(GIT_EINVALIDSPEC, git_reference_create( &new_reference, g_repo, name, &id, 0, NULL)); cl_assert_equal_i(GIT_EINVALIDSPEC, git_reference_symbolic_create( &new_reference, g_repo, name, current_head_target, 0, NULL)); }
// 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)); }
void test_refs_create__propagate_eexists(void) { int error; git_oid oid; git_reference *ref; /* Make sure it works for oid and for symbolic both */ git_oid_fromstr(&oid, current_master_tip); error = git_reference_create(&ref, g_repo, current_head_target, &oid, false, NULL); cl_assert(error == GIT_EEXISTS); error = git_reference_symbolic_create(&ref, g_repo, "HEAD", current_head_target, false, NULL); cl_assert(error == GIT_EEXISTS); }
/* * $ git init . * Initialized empty Git repository in d:/temp/tempee/.git/ * * $ touch a && git add a * $ git commit -m" boom" * [master (root-commit) b47b758] boom * 0 files changed * create mode 100644 a * * $ echo "ref: refs/heads/master" > .git/refs/heads/linked * $ echo "ref: refs/heads/linked" > .git/refs/heads/super * $ echo "ref: refs/heads/super" > .git/HEAD * * $ git branch * linked -> master * * master * super -> master */ void test_refs_branches_ishead__only_direct_references_are_considered(void) { git_reference *linked, *super, *head; git_repository_free(repo); repo = cl_git_sandbox_init("testrepo.git"); cl_git_pass(git_reference_symbolic_create(&linked, repo, "refs/heads/linked", "refs/heads/master", 0)); cl_git_pass(git_reference_symbolic_create(&super, repo, "refs/heads/super", "refs/heads/linked", 0)); cl_git_pass(git_reference_symbolic_create(&head, repo, GIT_HEAD_FILE, "refs/heads/super", 1)); cl_assert_equal_i(false, git_branch_is_head(linked)); cl_assert_equal_i(false, git_branch_is_head(super)); cl_git_pass(git_repository_head(&branch, repo)); cl_assert_equal_s("refs/heads/master", git_reference_name(branch)); git_reference_free(linked); git_reference_free(super); git_reference_free(head); cl_git_sandbox_cleanup(); repo = NULL; }
int git_rebase_finish( git_rebase *rebase, const git_signature *signature, const git_rebase_options *given_opts) { git_rebase_options opts; git_reference *terminal_ref = NULL, *branch_ref = NULL, *head_ref = NULL; git_commit *terminal_commit = NULL; git_buf branch_msg = GIT_BUF_INIT, head_msg = GIT_BUF_INIT; char onto[GIT_OID_HEXSZ]; int error; assert(rebase); GITERR_CHECK_VERSION(given_opts, GIT_REBASE_OPTIONS_VERSION, "git_rebase_options"); if ((error = rebase_normalize_opts(rebase->repo, &opts, given_opts)) < 0) goto done; git_oid_fmt(onto, &rebase->onto_id); if ((error = git_buf_printf(&branch_msg, "rebase finished: %s onto %.*s", rebase->orig_head_name, GIT_OID_HEXSZ, onto)) < 0 || (error = git_buf_printf(&head_msg, "rebase finished: returning to %s", rebase->orig_head_name)) < 0 || (error = git_repository_head(&terminal_ref, rebase->repo)) < 0 || (error = git_reference_peel((git_object **)&terminal_commit, terminal_ref, GIT_OBJ_COMMIT)) < 0 || (error = git_reference_create_matching(&branch_ref, rebase->repo, rebase->orig_head_name, git_commit_id(terminal_commit), 1, &rebase->orig_head_id, branch_msg.ptr)) < 0 || (error = git_reference_symbolic_create(&head_ref, rebase->repo, GIT_HEAD_FILE, rebase->orig_head_name, 1, head_msg.ptr)) < 0 || (error = rebase_copy_notes(rebase, signature, &opts)) < 0) goto done; error = rebase_cleanup(rebase); done: git_buf_free(&head_msg); git_buf_free(&branch_msg); git_commit_free(terminal_commit); git_reference_free(head_ref); git_reference_free(branch_ref); git_reference_free(terminal_ref); rebase_opts_free(&opts); return error; }
void test_network_remote_defaultbranch__unborn_HEAD_with_branches(void) { git_reference *ref; git_repository *cloned_repo; cl_git_pass(git_reference_symbolic_create(&ref, g_repo_a, "HEAD", "refs/heads/i-dont-exist", 1, NULL, NULL)); git_reference_free(ref); cl_git_pass(git_clone(&cloned_repo, git_repository_path(g_repo_a), "./semi-empty", NULL)); cl_assert(git_repository_head_unborn(cloned_repo)); git_repository_free(cloned_repo); }
void test_refs_create__creating_a_reference_with_an_invalid_name_returns_EINVALIDSPEC(void) { git_reference *new_reference; git_oid id; const char *name = "refs/heads/inv@{id"; git_oid_fromstr(&id, current_master_tip); cl_assert_equal_i(GIT_EINVALIDSPEC, git_reference_create( &new_reference, g_repo, name, &id, 0)); cl_assert_equal_i(GIT_EINVALIDSPEC, git_reference_symbolic_create( &new_reference, g_repo, name, current_head_target, 0)); }
void test_refs_overwrite__object_id_with_symbolic(void) { // Overwrite an existing object id reference with a symbolic 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); cl_git_pass(git_reference_create(&ref, g_repo, ref_name, &id, 0)); git_reference_free(ref); cl_git_fail(git_reference_symbolic_create(&ref, g_repo, ref_name, ref_master_name, 0)); cl_git_pass(git_reference_symbolic_create(&ref, g_repo, ref_name, ref_master_name, 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_SYMBOLIC); cl_assert_equal_s(git_reference_symbolic_target(ref), ref_master_name); git_reference_free(ref); }
int git_reference_symbolic_set_target( git_reference **out, git_reference *ref, const char *target) { assert(out && ref && target); if (ref->type != GIT_REF_SYMBOLIC) { giterr_set(GITERR_REFERENCE, "Cannot set symbolic target on a direct reference"); return -1; } return git_reference_symbolic_create(out, ref->db->repo, ref->name, target, 1); }
void test_merge_workdir_simple__directory_file(void) { git_reference *head; git_oid their_oids[1], head_commit_id; git_merge_head *their_heads[1]; git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT; git_commit *head_commit; struct merge_index_entry merge_index_entries[] = { { 0100644, "49130a28ef567af9a6a6104c38773fedfa5f9742", 2, "dir-10" }, { 0100644, "6c06dcd163587c2cc18be44857e0b71116382aeb", 3, "dir-10" }, { 0100644, "43aafd43bea779ec74317dc361f45ae3f532a505", 0, "dir-6" }, { 0100644, "a031a28ae70e33a641ce4b8a8f6317f1ab79dee4", 3, "dir-7" }, { 0100644, "5012fd565b1393bdfda1805d4ec38ce6619e1fd1", 1, "dir-7/file.txt" }, { 0100644, "a5563304ddf6caba25cb50323a2ea6f7dbfcadca", 2, "dir-7/file.txt" }, { 0100644, "e9ad6ec3e38364a3d07feda7c4197d4d845c53b5", 0, "dir-8" }, { 0100644, "3ef4d30382ca33fdeba9fda895a99e0891ba37aa", 2, "dir-9" }, { 0100644, "fc4c636d6515e9e261f9260dbcf3cc6eca97ea08", 1, "dir-9/file.txt" }, { 0100644, "76ab0e2868197ec158ddd6c78d8a0d2fd73d38f9", 3, "dir-9/file.txt" }, { 0100644, "5c2411f8075f48a6b2fdb85ebc0d371747c4df15", 0, "file-1/new" }, { 0100644, "a39a620dae5bc8b4e771cd4d251b7d080401a21e", 1, "file-2" }, { 0100644, "d963979c237d08b6ba39062ee7bf64c7d34a27f8", 2, "file-2" }, { 0100644, "5c341ead2ba6f2af98ce5ec3fe84f6b6d2899c0d", 0, "file-2/new" }, { 0100644, "9efe7723802d4305142eee177e018fee1572c4f4", 0, "file-3/new" }, { 0100644, "bacac9b3493509aa15e1730e1545fc0919d1dae0", 1, "file-4" }, { 0100644, "7663fce0130db092936b137cabd693ec234eb060", 3, "file-4" }, { 0100644, "e49f917b448d1340b31d76e54ba388268fd4c922", 0, "file-4/new" }, { 0100644, "cab2cf23998b40f1af2d9d9a756dc9e285a8df4b", 2, "file-5/new" }, { 0100644, "f5504f36e6f4eb797a56fc5bac6c6c7f32969bf2", 3, "file-5/new" }, }; cl_git_pass(git_reference_symbolic_create(&head, repo, GIT_HEAD_FILE, GIT_REFS_HEADS_DIR OURS_DIRECTORY_FILE, 1, NULL, NULL)); cl_git_pass(git_reference_name_to_id(&head_commit_id, repo, GIT_HEAD_FILE)); cl_git_pass(git_commit_lookup(&head_commit, repo, &head_commit_id)); cl_git_pass(git_reset(repo, (git_object *)head_commit, GIT_RESET_HARD, NULL, NULL)); cl_git_pass(git_oid_fromstr(&their_oids[0], THEIRS_DIRECTORY_FILE)); cl_git_pass(git_merge_head_from_id(&their_heads[0], repo, &their_oids[0])); merge_opts.file_favor = 0; cl_git_pass(git_merge(repo, (const git_merge_head **)their_heads, 1, &merge_opts, NULL)); cl_assert(merge_test_index(repo_index, merge_index_entries, 20)); git_reference_free(head); git_commit_free(head_commit); git_merge_head_free(their_heads[0]); }
void test_repo_head__unborn_head(void) { git_reference *ref; cl_git_pass(git_repository_head_detached(repo)); make_head_unborn(repo, NON_EXISTING_HEAD); cl_assert(git_repository_head_unborn(repo) == 1); /* take the repo back to it's original state */ cl_git_pass(git_reference_symbolic_create(&ref, repo, "HEAD", "refs/heads/master", 1, NULL)); cl_assert(git_repository_head_unborn(repo) == 0); git_reference_free(ref); }
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); }
/* * $ git branch -r * nulltoken/HEAD -> nulltoken/master * nulltoken/master */ void test_refs_branches_foreach__retrieve_remote_symbolic_HEAD_when_present(void) { struct expectations exp[] = { { "nulltoken/HEAD", 0 }, { "nulltoken/master", 0 }, { NULL, 0 } }; git_reference_free(fake_remote); cl_git_pass(git_reference_symbolic_create(&fake_remote, repo, "refs/remotes/nulltoken/HEAD", "refs/remotes/nulltoken/master", 0)); assert_retrieval(GIT_BRANCH_REMOTE, 3); cl_git_pass(git_branch_foreach(repo, GIT_BRANCH_REMOTE, contains_branch_list_cb, &exp)); assert_branch_has_been_found(exp, "nulltoken/HEAD"); assert_branch_has_been_found(exp, "nulltoken/HEAD"); }
PyObject * Repository_create_reference_symbolic(Repository *self, PyObject *args, PyObject *kw) { git_reference *c_reference; char *c_name, *c_target; int err, force; if (!PyArg_ParseTuple(args, "ssi", &c_name, &c_target, &force)) return NULL; err = git_reference_symbolic_create(&c_reference, self->repo, c_name, c_target, force, NULL, NULL); if (err < 0) return Error_set(err); return wrap_reference(c_reference, self); }
void test_repo_head__head_detached(void) { git_reference *ref; cl_assert_equal_i(false, git_repository_head_detached(repo)); cl_git_pass(git_repository_detach_head(repo)); check_last_reflog_entry(g_email, "checkout: moving from master to a65fedf39aefe402d3bb6e24df4d4f5fe4547750"); cl_assert_equal_i(true, git_repository_head_detached(repo)); /* take the repo back to it's original state */ cl_git_pass(git_reference_symbolic_create(&ref, repo, "HEAD", "refs/heads/master", true, "REATTACH")); git_reference_free(ref); check_last_reflog_entry(g_email, "REATTACH"); cl_assert_equal_i(false, git_repository_head_detached(repo)); }
void test_network_remote_rename__symref_head(void) { int error; git_reference *ref; git_branch_t btype; git_branch_iterator *iter; git_strarray problems = {0}; char idstr[GIT_OID_HEXSZ + 1] = {0}; git_vector refs; cl_git_pass(git_reference_symbolic_create(&ref, _repo, "refs/remotes/test/HEAD", "refs/remotes/test/master", 0, 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); cl_git_pass(git_vector_init(&refs, 2, (git_vector_cmp) git_reference_cmp)); cl_git_pass(git_branch_iterator_new(&iter, _repo, GIT_BRANCH_REMOTE)); while ((error = git_branch_next(&ref, &btype, iter)) == 0) { cl_git_pass(git_vector_insert(&refs, ref)); } cl_assert_equal_i(GIT_ITEROVER, error); git_vector_sort(&refs); cl_assert_equal_i(2, refs.length); ref = git_vector_get(&refs, 0); cl_assert_equal_s("refs/remotes/renamed/HEAD", git_reference_name(ref)); cl_assert_equal_s("refs/remotes/renamed/master", git_reference_symbolic_target(ref)); git_reference_free(ref); ref = git_vector_get(&refs, 1); 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); git_vector_free(&refs); cl_git_fail_with(GIT_ITEROVER, git_branch_next(&ref, &btype, iter)); git_branch_iterator_free(iter); }
void test_refs_create__deep_symbolic(void) { /* create a deep symbolic reference */ git_reference *new_reference, *looked_up_ref, *resolved_ref; git_oid id; const char *new_head_tracker = "deep/rooted/tracker"; git_oid_fromstr(&id, current_master_tip); cl_git_pass(git_reference_symbolic_create(&new_reference, g_repo, new_head_tracker, current_head_target, 0, NULL)); cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, new_head_tracker)); cl_git_pass(git_reference_resolve(&resolved_ref, looked_up_ref)); cl_assert_equal_oid(&id, git_reference_target(resolved_ref)); git_reference_free(new_reference); git_reference_free(looked_up_ref); git_reference_free(resolved_ref); }
void test_refs_create__symbolic(void) { /* create a new symbolic reference */ git_reference *new_reference, *looked_up_ref, *resolved_ref; git_repository *repo2; git_oid id; const char *new_head_tracker = "ANOTHER_HEAD_TRACKER"; git_oid_fromstr(&id, current_master_tip); /* Create and write the new symbolic reference */ cl_git_pass(git_reference_symbolic_create(&new_reference, g_repo, new_head_tracker, current_head_target, 0, NULL)); /* Ensure the reference can be looked-up... */ cl_git_pass(git_reference_lookup(&looked_up_ref, g_repo, new_head_tracker)); cl_assert(git_reference_type(looked_up_ref) & GIT_REF_SYMBOLIC); cl_assert(reference_is_packed(looked_up_ref) == 0); cl_assert_equal_s(looked_up_ref->name, new_head_tracker); /* ...peeled.. */ cl_git_pass(git_reference_resolve(&resolved_ref, looked_up_ref)); cl_assert(git_reference_type(resolved_ref) == GIT_REF_OID); /* ...and that it points to the current master tip */ cl_assert_equal_oid(&id, git_reference_target(resolved_ref)); git_reference_free(looked_up_ref); git_reference_free(resolved_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_tracker)); cl_git_pass(git_reference_resolve(&resolved_ref, looked_up_ref)); cl_assert_equal_oid(&id, git_reference_target(resolved_ref)); git_repository_free(repo2); git_reference_free(new_reference); git_reference_free(looked_up_ref); git_reference_free(resolved_ref); }