Merge pull request #974 from nulltoken/EEXISTS Enforce returning of EEXISTS when trying to overwrite a reference
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
diff --git a/src/branch.c b/src/branch.c
index 6d497b0..d0bd1c4 100644
--- a/src/branch.c
+++ b/src/branch.c
@@ -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);
diff --git a/src/refs.c b/src/refs.c
index 9dc422e..1d73b26 100644
--- a/src/refs.c
+++ b/src/refs.c
@@ -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. */
diff --git a/tests-clar/object/tag/write.c b/tests-clar/object/tag/write.c
index cb196b6..10d0479 100644
--- a/tests-clar/object/tag/write.c
+++ b/tests-clar/object/tag/write.c
@@ -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",
diff --git a/tests-clar/refs/branches/create.c b/tests-clar/refs/branches/create.c
index fe72d47..9026b0d 100644
--- a/tests-clar/refs/branches/create.c
+++ b/tests-clar/refs/branches/create.c
@@ -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)
diff --git a/tests-clar/refs/branches/move.c b/tests-clar/refs/branches/move.c
index 9ab7da4..62b6042 100644
--- a/tests-clar/refs/branches/move.c
+++ b/tests-clar/refs/branches/move.c
@@ -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)
diff --git a/tests-clar/refs/rename.c b/tests-clar/refs/rename.c
index 4b917ef..19bf875 100644
--- a/tests-clar/refs/rename.c
+++ b/tests-clar/refs/rename.c
@@ -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);
+}