mirror of
https://git.proxmox.com/git/libgit2
synced 2025-08-05 03:33:23 +00:00
branch: Add repository
argument to create
Yes, we can get the repository from the owner of the object, but having it marked explicitly makes the API more consistent.
This commit is contained in:
parent
b41a30bdbb
commit
f0244463ad
@ -47,6 +47,7 @@ GIT_BEGIN_DECL
|
||||
*/
|
||||
GIT_EXTERN(int) git_branch_create(
|
||||
git_reference **branch_out,
|
||||
git_repository *repo,
|
||||
const char *branch_name,
|
||||
const git_object *target,
|
||||
int force);
|
||||
|
@ -52,6 +52,7 @@ static int create_error_invalid(const char *msg)
|
||||
|
||||
int git_branch_create(
|
||||
git_reference **ref_out,
|
||||
git_repository *repository,
|
||||
const char *branch_name,
|
||||
const git_object *target,
|
||||
int force)
|
||||
@ -63,6 +64,7 @@ int git_branch_create(
|
||||
int error = -1;
|
||||
|
||||
assert(branch_name && target && ref_out);
|
||||
assert(git_object_owner(target) == repository);
|
||||
|
||||
target_type = git_object_type(target);
|
||||
|
||||
@ -89,7 +91,7 @@ int git_branch_create(
|
||||
if (git_buf_joinpath(&canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (git_reference_create_oid(&branch, git_object_owner(commit),
|
||||
if (git_reference_create_oid(&branch, repository,
|
||||
git_buf_cstr(&canonical_branch_name), git_object_id(commit), force) < 0)
|
||||
goto cleanup;
|
||||
|
||||
@ -224,7 +226,8 @@ int git_branch_lookup(
|
||||
return retrieve_branch_reference(ref_out, repo, branch_name, branch_type == GIT_BRANCH_REMOTE);
|
||||
}
|
||||
|
||||
int retrieve_tracking_configuration(const char **out, git_reference *branch, const char *format)
|
||||
static int retrieve_tracking_configuration(
|
||||
const char **out, git_reference *branch, const char *format)
|
||||
{
|
||||
git_config *config;
|
||||
git_buf buf = GIT_BUF_INIT;
|
||||
|
@ -183,7 +183,7 @@ static int retrieve_reflog_path(git_buf *path, git_reference *ref)
|
||||
git_reference_owner(ref)->path_repository, GIT_REFLOG_DIR, ref->name);
|
||||
}
|
||||
|
||||
int create_new_reflog_file(const char *filepath)
|
||||
static int create_new_reflog_file(const char *filepath)
|
||||
{
|
||||
int fd;
|
||||
|
||||
|
@ -42,7 +42,7 @@ void test_refs_branches_create__can_create_a_local_branch(void)
|
||||
{
|
||||
retrieve_known_commit(&target, repo);
|
||||
|
||||
cl_git_pass(git_branch_create(&branch, NEW_BRANCH_NAME, target, 0));
|
||||
cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, 0));
|
||||
cl_git_pass(git_oid_cmp(git_reference_oid(branch), git_object_id(target)));
|
||||
}
|
||||
|
||||
@ -50,14 +50,14 @@ void test_refs_branches_create__can_not_create_a_branch_if_its_name_collide_with
|
||||
{
|
||||
retrieve_known_commit(&target, repo);
|
||||
|
||||
cl_git_fail(git_branch_create(&branch, "br2", target, 0));
|
||||
cl_git_fail(git_branch_create(&branch, repo, "br2", target, 0));
|
||||
}
|
||||
|
||||
void test_refs_branches_create__can_force_create_over_an_existing_branch(void)
|
||||
{
|
||||
retrieve_known_commit(&target, repo);
|
||||
|
||||
cl_git_pass(git_branch_create(&branch, "br2", target, 1));
|
||||
cl_git_pass(git_branch_create(&branch, repo, "br2", target, 1));
|
||||
cl_git_pass(git_oid_cmp(git_reference_oid(branch), git_object_id(target)));
|
||||
cl_assert_equal_s("refs/heads/br2", git_reference_name(branch));
|
||||
}
|
||||
@ -67,7 +67,7 @@ void test_refs_branches_create__creating_a_branch_targeting_a_tag_dereferences_i
|
||||
/* b25fa35 is a tag, pointing to another tag which points to a commit */
|
||||
retrieve_target_from_oid(&target, repo, "b25fa35b38051e4ae45d4222e795f9df2e43f1d1");
|
||||
|
||||
cl_git_pass(git_branch_create(&branch, NEW_BRANCH_NAME, target, 0));
|
||||
cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, 0));
|
||||
cl_git_pass(git_oid_streq(git_reference_oid(branch), "e90810b8df3e80c413d903f631643c716887138d"));
|
||||
}
|
||||
|
||||
@ -76,11 +76,11 @@ void test_refs_branches_create__can_not_create_a_branch_pointing_to_a_non_commit
|
||||
/* 53fc32d is the tree of commit e90810b */
|
||||
retrieve_target_from_oid(&target, repo, "53fc32d17276939fc79ed05badaef2db09990016");
|
||||
|
||||
cl_git_fail(git_branch_create(&branch, NEW_BRANCH_NAME, target, 0));
|
||||
cl_git_fail(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, 0));
|
||||
git_object_free(target);
|
||||
|
||||
/* 521d87c is an annotated tag pointing to a blob */
|
||||
retrieve_target_from_oid(&target, repo, "521d87c1ec3aef9824daf6d96cc0ae3710766d91");
|
||||
|
||||
cl_git_fail(git_branch_create(&branch, NEW_BRANCH_NAME, target, 0));
|
||||
cl_git_fail(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, 0));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user