Commit 1d08b72e4fbc474719baec127d7911cc116dec48

Linquize 2014-03-02T19:14:20

Add unit test to show git_branch_create() fails if attempt to force create current branch

diff --git a/tests/refs/branches/create.c b/tests/refs/branches/create.c
index abe5f59..d4b0763 100644
--- a/tests/refs/branches/create.c
+++ b/tests/refs/branches/create.c
@@ -66,6 +66,25 @@ void test_refs_branches_create__can_force_create_over_an_existing_branch(void)
 	cl_assert_equal_s("refs/heads/br2", git_reference_name(branch));
 }
 
+void test_refs_branches_create__cannot_force_create_over_current_branch(void)
+{
+	const git_oid *oid;
+	git_reference *branch2;
+	retrieve_known_commit(&target, repo);
+
+	cl_git_pass(git_branch_lookup(&branch2, repo, "master", GIT_BRANCH_LOCAL));
+	cl_assert_equal_s("refs/heads/master", git_reference_name(branch2));
+	cl_assert_equal_i(true, git_branch_is_head(branch2));
+	oid = git_reference_target(branch2);
+
+	cl_git_fail_with(-1, git_branch_create(&branch, repo, "master", target, 1, NULL, NULL));
+	branch = NULL;
+	cl_git_pass(git_branch_lookup(&branch, repo, "master", GIT_BRANCH_LOCAL));
+	cl_assert_equal_s("refs/heads/master", git_reference_name(branch));
+	cl_git_pass(git_oid_cmp(git_reference_target(branch), oid));
+	git_reference_free(branch2);
+}
+
 void test_refs_branches_create__creating_a_branch_with_an_invalid_name_returns_EINVALIDSPEC(void)
 {
 	retrieve_known_commit(&target, repo);