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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
diff --git a/include/git2/branch.h b/include/git2/branch.h
index 15894b7..2f46720 100644
--- a/include/git2/branch.h
+++ b/include/git2/branch.h
@@ -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);
diff --git a/src/branch.c b/src/branch.c
index d11eca8..52fed67 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -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;
diff --git a/src/reflog.c b/src/reflog.c
index 445e539..53cc25f 100644
--- a/src/reflog.c
+++ b/src/reflog.c
@@ -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;
diff --git a/tests-clar/refs/branches/create.c b/tests-clar/refs/branches/create.c
index d539043..fe72d47 100644
--- a/tests-clar/refs/branches/create.c
+++ b/tests-clar/refs/branches/create.c
@@ -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));
}