Commit 80a6e86b by Ben Straub

Merge pull request #974 from nulltoken/EEXISTS

 Enforce returning of EEXISTS when trying to overwrite a reference
parents 26ddcfa4 b73200c1
......@@ -77,12 +77,11 @@ 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, repository,
git_buf_cstr(&canonical_branch_name), git_object_id(commit), force) < 0)
goto cleanup;
error = git_reference_create_oid(&branch, repository,
git_buf_cstr(&canonical_branch_name), git_object_id(commit), force);
*ref_out = branch;
error = 0;
if (!error)
*ref_out = branch;
cleanup:
git_object_free(commit);
......
......@@ -1357,8 +1357,8 @@ int git_reference_rename(git_reference *ref, const char *new_name, int force)
normalization_flags) < 0)
return -1;
if (reference_can_write(ref->owner, normalized, ref->name, force) < 0)
return -1;
if ((result = reference_can_write(ref->owner, normalized, ref->name, force)) < 0)
return result;
/* Initialize path now so we won't get an allocation failure once
* we actually start removing things. */
......
......@@ -77,7 +77,7 @@ void test_object_tag_write__overwrite(void)
/* create signature */
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 */
g_repo,
"e90810b",
......@@ -166,7 +166,7 @@ void test_object_tag_write__lightweight_over_existing(void)
git_oid_fromstr(&target_id, tagged_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,
g_repo,
"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);
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)
......
......@@ -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)
{
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)
......
......@@ -337,3 +337,14 @@ void test_refs_rename__move_up(void)
git_reference_free(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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment