void test_repo_head__head_orphan(void) { git_reference *ref; cl_assert(git_repository_head_orphan(repo) == 0); /* orphan HEAD */ cl_git_pass(git_reference_create_symbolic(&ref, repo, "HEAD", "refs/heads/orphan", 1)); cl_assert(git_repository_head_orphan(repo) == 1); git_reference_free(ref); /* take the reop back to it's original state */ cl_git_pass(git_reference_create_symbolic(&ref, repo, "HEAD", "refs/heads/master", 1)); cl_assert(git_repository_head_orphan(repo) == 0); git_reference_free(ref); }
void test_repo_head__detach_head_Fails_if_HEAD_and_point_to_a_non_commitish(void) { git_reference *head; cl_git_pass(git_reference_create_symbolic(&head, repo, GIT_HEAD_FILE, "refs/tags/point_to_blob", 1)); cl_git_fail(git_repository_detach_head(repo)); git_reference_free(head); }
/* * $ git branch -r * nulltoken/HEAD -> nulltoken/master * nulltoken/master */ void test_refs_branches_listall__retrieve_remote_symbolic_HEAD_when_present(void) { git_reference_free(fake_remote); cl_git_pass(git_reference_create_symbolic(&fake_remote, repo, "refs/remotes/nulltoken/HEAD", "refs/remotes/nulltoken/master", 0)); cl_git_pass(git_branch_list(&branch_list, repo, GIT_BRANCH_REMOTE)); cl_assert_equal_i(2, branch_list.count); assert_branch_list_contains(&branch_list, "refs/remotes/nulltoken/HEAD"); assert_branch_list_contains(&branch_list, "refs/remotes/nulltoken/master"); }
/* * $ 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_create_symbolic(&linked, repo, "refs/heads/linked", "refs/heads/master", 0)); cl_git_pass(git_reference_create_symbolic(&super, repo, "refs/heads/super", "refs/heads/linked", 0)); cl_git_pass(git_reference_create_symbolic(&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; }
void test_repo_head__head_detached(void) { git_reference *ref; git_oid oid; cl_assert(git_repository_head_detached(repo) == 0); /* detach the HEAD */ git_oid_fromstr(&oid, "c47800c7266a2be04c571c04d5a6614691ea99bd"); cl_git_pass(git_reference_create_oid(&ref, repo, "HEAD", &oid, 1)); cl_assert(git_repository_head_detached(repo) == 1); git_reference_free(ref); /* take the reop back to it's original state */ cl_git_pass(git_reference_create_symbolic(&ref, repo, "HEAD", "refs/heads/master", 1)); cl_assert(git_repository_head_detached(repo) == 0); git_reference_free(ref); }
PyObject * Repository_create_symbolic_reference(Repository *self, PyObject *args) { git_reference *c_reference; char *c_name, *c_target; int err; /* 1- Get the C variables */ if (!PyArg_ParseTuple(args, "ss", &c_name, &c_target)) return NULL; /* 2- Create the reference */ err = git_reference_create_symbolic(&c_reference, self->repo, c_name, c_target, 0); if (err < 0) return Error_set(err); /* 3- Make an instance of Reference and return it */ return wrap_reference(c_reference); }
git_reference *new_reference, *looked_up_ref, *resolved_ref; git_repository *repo, *repo2; git_oid id; char ref_path[GIT_PATH_MAX]; const char *new_head_tracker = "another-head-tracker"; git_oid_fromstr(&id, current_master_tip); must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); /* Retrieve the physical path to the symbolic ref for further cleaning */ git_path_join(ref_path, repo->path_repository, new_head_tracker); /* Create and write the new symbolic reference */ must_pass(git_reference_create_symbolic(&new_reference, repo, new_head_tracker, current_head_target, 0)); /* Ensure the reference can be looked-up... */ must_pass(git_reference_lookup(&looked_up_ref, repo, new_head_tracker)); must_be_true(looked_up_ref->type & GIT_REF_SYMBOLIC); must_be_true((looked_up_ref->type & GIT_REF_PACKED) == 0); must_be_true(strcmp(looked_up_ref->name, new_head_tracker) == 0); /* ...peeled.. */ must_pass(git_reference_resolve(&resolved_ref, looked_up_ref)); must_be_true(resolved_ref->type == GIT_REF_OID); /* ...and that it points to the current master tip */ must_be_true(git_oid_cmp(&id, git_reference_oid(resolved_ref)) == 0); git_repository_free(repo);
static int repo_init_createhead(git_repository *repo) { git_reference *head_reference; return git_reference_create_symbolic(&head_reference, repo, GIT_HEAD_FILE, GIT_REFS_HEADS_MASTER_FILE); }