mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-08 22:08:56 +00:00
Merge pull request #974 from nulltoken/EEXISTS
Enforce returning of EEXISTS when trying to overwrite a reference
This commit is contained in:
commit
80a6e86bb6
@ -77,12 +77,11 @@ int git_branch_create(
|
|||||||
if (git_buf_joinpath(&canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name) < 0)
|
if (git_buf_joinpath(&canonical_branch_name, GIT_REFS_HEADS_DIR, branch_name) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (git_reference_create_oid(&branch, repository,
|
error = git_reference_create_oid(&branch, repository,
|
||||||
git_buf_cstr(&canonical_branch_name), git_object_id(commit), force) < 0)
|
git_buf_cstr(&canonical_branch_name), git_object_id(commit), force);
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
*ref_out = branch;
|
if (!error)
|
||||||
error = 0;
|
*ref_out = branch;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
git_object_free(commit);
|
git_object_free(commit);
|
||||||
|
@ -1357,8 +1357,8 @@ int git_reference_rename(git_reference *ref, const char *new_name, int force)
|
|||||||
normalization_flags) < 0)
|
normalization_flags) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (reference_can_write(ref->owner, normalized, ref->name, force) < 0)
|
if ((result = reference_can_write(ref->owner, normalized, ref->name, force)) < 0)
|
||||||
return -1;
|
return result;
|
||||||
|
|
||||||
/* Initialize path now so we won't get an allocation failure once
|
/* Initialize path now so we won't get an allocation failure once
|
||||||
* we actually start removing things. */
|
* we actually start removing things. */
|
||||||
|
@ -77,7 +77,7 @@ void test_object_tag_write__overwrite(void)
|
|||||||
/* create signature */
|
/* create signature */
|
||||||
cl_git_pass(git_signature_new(&tagger, tagger_name, tagger_email, 123456789, 60));
|
cl_git_pass(git_signature_new(&tagger, tagger_name, tagger_email, 123456789, 60));
|
||||||
|
|
||||||
cl_git_fail(git_tag_create(
|
cl_assert_equal_i(GIT_EEXISTS, git_tag_create(
|
||||||
&tag_id, /* out id */
|
&tag_id, /* out id */
|
||||||
g_repo,
|
g_repo,
|
||||||
"e90810b",
|
"e90810b",
|
||||||
@ -166,7 +166,7 @@ void test_object_tag_write__lightweight_over_existing(void)
|
|||||||
git_oid_fromstr(&target_id, tagged_commit);
|
git_oid_fromstr(&target_id, tagged_commit);
|
||||||
cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJ_COMMIT));
|
cl_git_pass(git_object_lookup(&target, g_repo, &target_id, GIT_OBJ_COMMIT));
|
||||||
|
|
||||||
cl_git_fail(git_tag_create_lightweight(
|
cl_assert_equal_i(GIT_EEXISTS, git_tag_create_lightweight(
|
||||||
&object_id,
|
&object_id,
|
||||||
g_repo,
|
g_repo,
|
||||||
"e90810b",
|
"e90810b",
|
||||||
|
@ -50,7 +50,7 @@ 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_git_fail(git_branch_create(&branch, repo, "br2", target, 0));
|
cl_assert_equal_i(GIT_EEXISTS, git_branch_create(&branch, repo, "br2", target, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
|
@ -45,7 +45,7 @@ void test_refs_branches_move__can_move_a_local_branch_to_a_partially_colliding_n
|
|||||||
|
|
||||||
void test_refs_branches_move__can_not_move_a_branch_if_its_destination_name_collide_with_an_existing_one(void)
|
void test_refs_branches_move__can_not_move_a_branch_if_its_destination_name_collide_with_an_existing_one(void)
|
||||||
{
|
{
|
||||||
cl_git_fail(git_branch_move(ref, "master", 0));
|
cl_assert_equal_i(GIT_EEXISTS, git_branch_move(ref, "master", 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_refs_branches_move__can_not_move_a_non_branch(void)
|
void test_refs_branches_move__can_not_move_a_non_branch(void)
|
||||||
|
@ -337,3 +337,14 @@ void test_refs_rename__move_up(void)
|
|||||||
git_reference_free(ref);
|
git_reference_free(ref);
|
||||||
git_reference_free(looked_up_ref);
|
git_reference_free(looked_up_ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_refs_rename__propagate_eexists(void)
|
||||||
|
{
|
||||||
|
git_reference *ref;
|
||||||
|
|
||||||
|
cl_git_pass(git_reference_lookup(&ref, g_repo, packed_head_name));
|
||||||
|
|
||||||
|
cl_assert_equal_i(GIT_EEXISTS, git_reference_rename(ref, packed_test_head_name, 0));
|
||||||
|
|
||||||
|
git_reference_free(ref);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user