mirror of
https://git.proxmox.com/git/libgit2
synced 2025-06-21 16:56:53 +00:00
Add reflog params to git_branch_create
This commit is contained in:
parent
67c4716f74
commit
b31ebfbc66
@ -43,6 +43,10 @@ GIT_BEGIN_DECL
|
|||||||
*
|
*
|
||||||
* @param force Overwrite existing branch.
|
* @param force Overwrite existing branch.
|
||||||
*
|
*
|
||||||
|
* @param signature The identity that will used to populate the reflog entry
|
||||||
|
*
|
||||||
|
* @param log_message The one line long message to be appended to the reflog
|
||||||
|
*
|
||||||
* @return 0, GIT_EINVALIDSPEC or an error code.
|
* @return 0, GIT_EINVALIDSPEC or an error code.
|
||||||
* A proper reference is written in the refs/heads namespace
|
* A proper reference is written in the refs/heads namespace
|
||||||
* pointing to the provided target commit.
|
* pointing to the provided target commit.
|
||||||
@ -52,7 +56,9 @@ GIT_EXTERN(int) git_branch_create(
|
|||||||
git_repository *repo,
|
git_repository *repo,
|
||||||
const char *branch_name,
|
const char *branch_name,
|
||||||
const git_commit *target,
|
const git_commit *target,
|
||||||
int force);
|
int force,
|
||||||
|
const git_signature *signature,
|
||||||
|
const char *log_message);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete an existing branch reference.
|
* Delete an existing branch reference.
|
||||||
|
16
src/branch.c
16
src/branch.c
@ -54,7 +54,9 @@ int git_branch_create(
|
|||||||
git_repository *repository,
|
git_repository *repository,
|
||||||
const char *branch_name,
|
const char *branch_name,
|
||||||
const git_commit *commit,
|
const git_commit *commit,
|
||||||
int force)
|
int force,
|
||||||
|
const git_signature *signature,
|
||||||
|
const char *log_message)
|
||||||
{
|
{
|
||||||
git_reference *branch = NULL;
|
git_reference *branch = NULL;
|
||||||
git_buf canonical_branch_name = GIT_BUF_INIT;
|
git_buf canonical_branch_name = GIT_BUF_INIT;
|
||||||
@ -63,14 +65,14 @@ int git_branch_create(
|
|||||||
assert(branch_name && commit && ref_out);
|
assert(branch_name && commit && ref_out);
|
||||||
assert(git_object_owner((const git_object *)commit) == repository);
|
assert(git_object_owner((const git_object *)commit) == repository);
|
||||||
|
|
||||||
if (!(error = git_buf_joinpath(
|
if (git_buf_joinpath(&canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name) < 0)
|
||||||
&canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name)))
|
goto cleanup;
|
||||||
error = git_reference_create(
|
|
||||||
&branch, repository, git_buf_cstr(&canonical_branch_name),
|
|
||||||
git_commit_id(commit), force, NULL, NULL);
|
|
||||||
|
|
||||||
*ref_out = branch;
|
if (!(error = git_reference_create(&branch, repository,
|
||||||
|
git_buf_cstr(&canonical_branch_name), git_commit_id(commit), force, signature, log_message)))
|
||||||
|
*ref_out = branch;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
git_buf_free(&canonical_branch_name);
|
git_buf_free(&canonical_branch_name);
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ static int create_branch(
|
|||||||
return error;
|
return error;
|
||||||
|
|
||||||
/* Create the new branch */
|
/* Create the new branch */
|
||||||
error = git_branch_create(&branch_ref, repo, name, head_obj, 0);
|
error = git_branch_create(&branch_ref, repo, name, head_obj, 0, NULL, NULL);
|
||||||
|
|
||||||
git_commit_free(head_obj);
|
git_commit_free(head_obj);
|
||||||
|
|
||||||
|
@ -480,7 +480,7 @@ void assert_conflict(
|
|||||||
/* Create a branch pointing at the parent */
|
/* Create a branch pointing at the parent */
|
||||||
cl_git_pass(git_revparse_single(&g_object, g_repo, parent_sha));
|
cl_git_pass(git_revparse_single(&g_object, g_repo, parent_sha));
|
||||||
cl_git_pass(git_branch_create(&branch, g_repo,
|
cl_git_pass(git_branch_create(&branch, g_repo,
|
||||||
"potential_conflict", (git_commit *)g_object, 0));
|
"potential_conflict", (git_commit *)g_object, 0, NULL, NULL));
|
||||||
|
|
||||||
/* Make HEAD point to this branch */
|
/* Make HEAD point to this branch */
|
||||||
cl_git_pass(git_reference_symbolic_create(
|
cl_git_pass(git_reference_symbolic_create(
|
||||||
|
@ -46,7 +46,7 @@ void test_refs_branches_create__can_create_a_local_branch(void)
|
|||||||
{
|
{
|
||||||
retrieve_known_commit(&target, repo);
|
retrieve_known_commit(&target, repo);
|
||||||
|
|
||||||
cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, 0));
|
cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, 0, NULL, NULL));
|
||||||
cl_git_pass(git_oid_cmp(git_reference_target(branch), git_commit_id(target)));
|
cl_git_pass(git_oid_cmp(git_reference_target(branch), git_commit_id(target)));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,14 +54,14 @@ void test_refs_branches_create__can_not_create_a_branch_if_its_name_collide_with
|
|||||||
{
|
{
|
||||||
retrieve_known_commit(&target, repo);
|
retrieve_known_commit(&target, repo);
|
||||||
|
|
||||||
cl_assert_equal_i(GIT_EEXISTS, git_branch_create(&branch, repo, "br2", target, 0));
|
cl_assert_equal_i(GIT_EEXISTS, git_branch_create(&branch, repo, "br2", target, 0, NULL, NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_refs_branches_create__can_force_create_over_an_existing_branch(void)
|
void test_refs_branches_create__can_force_create_over_an_existing_branch(void)
|
||||||
{
|
{
|
||||||
retrieve_known_commit(&target, repo);
|
retrieve_known_commit(&target, repo);
|
||||||
|
|
||||||
cl_git_pass(git_branch_create(&branch, repo, "br2", target, 1));
|
cl_git_pass(git_branch_create(&branch, repo, "br2", target, 1, NULL, NULL));
|
||||||
cl_git_pass(git_oid_cmp(git_reference_target(branch), git_commit_id(target)));
|
cl_git_pass(git_oid_cmp(git_reference_target(branch), git_commit_id(target)));
|
||||||
cl_assert_equal_s("refs/heads/br2", git_reference_name(branch));
|
cl_assert_equal_s("refs/heads/br2", git_reference_name(branch));
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ void test_refs_branches_create__creating_a_branch_with_an_invalid_name_returns_E
|
|||||||
retrieve_known_commit(&target, repo);
|
retrieve_known_commit(&target, repo);
|
||||||
|
|
||||||
cl_assert_equal_i(GIT_EINVALIDSPEC,
|
cl_assert_equal_i(GIT_EINVALIDSPEC,
|
||||||
git_branch_create(&branch, repo, "inv@{id", target, 0));
|
git_branch_create(&branch, repo, "inv@{id", target, 0, NULL, NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_refs_branches_create__creation_creates_new_reflog(void)
|
void test_refs_branches_create__creation_creates_new_reflog(void)
|
||||||
@ -80,26 +80,30 @@ void test_refs_branches_create__creation_creates_new_reflog(void)
|
|||||||
const git_reflog_entry *entry;
|
const git_reflog_entry *entry;
|
||||||
|
|
||||||
retrieve_known_commit(&target, repo);
|
retrieve_known_commit(&target, repo);
|
||||||
cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, false));
|
cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, false, NULL, "create!"));
|
||||||
cl_git_pass(git_reflog_read(&log, repo, "refs/heads/" NEW_BRANCH_NAME));
|
cl_git_pass(git_reflog_read(&log, repo, "refs/heads/" NEW_BRANCH_NAME));
|
||||||
|
|
||||||
cl_assert_equal_i(1, git_reflog_entrycount(log));
|
cl_assert_equal_i(1, git_reflog_entrycount(log));
|
||||||
entry = git_reflog_entry_byindex(log, 0);
|
entry = git_reflog_entry_byindex(log, 0);
|
||||||
|
cl_assert_equal_s("create!", git_reflog_entry_message(entry));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_refs_branches_create__recreation_updates_existing_reflog(void)
|
void test_refs_branches_create__recreation_updates_existing_reflog(void)
|
||||||
{
|
{
|
||||||
git_reflog *log;
|
git_reflog *log;
|
||||||
const git_reflog_entry *entry;
|
const git_reflog_entry *entry1, *entry2;
|
||||||
|
|
||||||
retrieve_known_commit(&target, repo);
|
retrieve_known_commit(&target, repo);
|
||||||
|
|
||||||
cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, false));
|
cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, false, NULL, "Create 1"));
|
||||||
cl_git_pass(git_branch_delete(branch));
|
cl_git_pass(git_branch_delete(branch));
|
||||||
cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, false));
|
cl_git_pass(git_branch_create(&branch, repo, NEW_BRANCH_NAME, target, false, NULL, "Create 2"));
|
||||||
cl_git_pass(git_reflog_read(&log, repo, "refs/heads/" NEW_BRANCH_NAME));
|
cl_git_pass(git_reflog_read(&log, repo, "refs/heads/" NEW_BRANCH_NAME));
|
||||||
|
|
||||||
cl_assert_equal_i(2, git_reflog_entrycount(log));
|
cl_assert_equal_i(2, git_reflog_entrycount(log));
|
||||||
entry = git_reflog_entry_byindex(log, 0);
|
entry1 = git_reflog_entry_byindex(log, 1);
|
||||||
|
entry2 = git_reflog_entry_byindex(log, 0);
|
||||||
|
cl_assert_equal_s("Create 1", git_reflog_entry_message(entry1));
|
||||||
|
cl_assert_equal_s("Create 2", git_reflog_entry_message(entry2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ static void assert_merge_and_or_remote_key_missing(git_repository *repository, c
|
|||||||
git_reference *branch;
|
git_reference *branch;
|
||||||
|
|
||||||
cl_assert_equal_i(GIT_OBJ_COMMIT, git_object_type((git_object*)target));
|
cl_assert_equal_i(GIT_OBJ_COMMIT, git_object_type((git_object*)target));
|
||||||
cl_git_pass(git_branch_create(&branch, repository, entry_name, (git_commit*)target, 0));
|
cl_git_pass(git_branch_create(&branch, repository, entry_name, (git_commit*)target, 0, NULL, NULL));
|
||||||
|
|
||||||
cl_assert_equal_i(GIT_ENOTFOUND, git_branch_upstream(&upstream, branch));
|
cl_assert_equal_i(GIT_ENOTFOUND, git_branch_upstream(&upstream, branch));
|
||||||
|
|
||||||
|
@ -634,7 +634,7 @@ void test_refs_revparse__try_to_retrieve_branch_before_described_tag(void)
|
|||||||
test_object_inrepo("blah-7-gc47800c", "c47800c7266a2be04c571c04d5a6614691ea99bd", repo);
|
test_object_inrepo("blah-7-gc47800c", "c47800c7266a2be04c571c04d5a6614691ea99bd", repo);
|
||||||
|
|
||||||
cl_git_pass(git_revparse_single(&target, repo, "HEAD~3"));
|
cl_git_pass(git_revparse_single(&target, repo, "HEAD~3"));
|
||||||
cl_git_pass(git_branch_create(&branch, repo, "blah-7-gc47800c", (git_commit *)target, 0));
|
cl_git_pass(git_branch_create(&branch, repo, "blah-7-gc47800c", (git_commit *)target, 0, NULL, NULL));
|
||||||
|
|
||||||
git_oid_tostr(sha, GIT_OID_HEXSZ + 1, git_object_id(target));
|
git_oid_tostr(sha, GIT_OID_HEXSZ + 1, git_object_id(target));
|
||||||
|
|
||||||
@ -672,7 +672,7 @@ void test_refs_revparse__try_to_retrieve_sha_before_branch(void)
|
|||||||
test_object_inrepo("a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", repo);
|
test_object_inrepo("a65fedf39aefe402d3bb6e24df4d4f5fe4547750", "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", repo);
|
||||||
|
|
||||||
cl_git_pass(git_revparse_single(&target, repo, "HEAD~3"));
|
cl_git_pass(git_revparse_single(&target, repo, "HEAD~3"));
|
||||||
cl_git_pass(git_branch_create(&branch, repo, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", (git_commit *)target, 0));
|
cl_git_pass(git_branch_create(&branch, repo, "a65fedf39aefe402d3bb6e24df4d4f5fe4547750", (git_commit *)target, 0, NULL, NULL));
|
||||||
|
|
||||||
git_oid_tostr(sha, GIT_OID_HEXSZ + 1, git_object_id(target));
|
git_oid_tostr(sha, GIT_OID_HEXSZ + 1, git_object_id(target));
|
||||||
|
|
||||||
@ -708,7 +708,7 @@ void test_refs_revparse__try_to_retrieve_branch_before_abbrev_sha(void)
|
|||||||
test_object_inrepo("c47800", "c47800c7266a2be04c571c04d5a6614691ea99bd", repo);
|
test_object_inrepo("c47800", "c47800c7266a2be04c571c04d5a6614691ea99bd", repo);
|
||||||
|
|
||||||
cl_git_pass(git_revparse_single(&target, repo, "HEAD~3"));
|
cl_git_pass(git_revparse_single(&target, repo, "HEAD~3"));
|
||||||
cl_git_pass(git_branch_create(&branch, repo, "c47800", (git_commit *)target, 0));
|
cl_git_pass(git_branch_create(&branch, repo, "c47800", (git_commit *)target, 0, NULL, NULL));
|
||||||
|
|
||||||
git_oid_tostr(sha, GIT_OID_HEXSZ + 1, git_object_id(target));
|
git_oid_tostr(sha, GIT_OID_HEXSZ + 1, git_object_id(target));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user