@@ -65,10 +65,14 @@ void test_refs_branches_create__can_force_create_over_an_existing_branch(void)
6565 cl_assert_equal_s ("refs/heads/br2" , git_reference_name (branch ));
6666}
6767
68- void test_refs_branches_create__cannot_force_create_over_current_branch (void )
68+ void test_refs_branches_create__cannot_force_create_over_current_branch_in_nonbare_repo (void )
6969{
7070 const git_oid * oid ;
7171 git_reference * branch2 ;
72+
73+ /* Default repo for these tests is a bare repo, but this test requires a non-bare one */
74+ cl_git_sandbox_cleanup ();
75+ repo = cl_git_sandbox_init ("testrepo" );
7276 retrieve_known_commit (& target , repo );
7377
7478 cl_git_pass (git_branch_lookup (& branch2 , repo , "master" , GIT_BRANCH_LOCAL ));
@@ -84,6 +88,26 @@ void test_refs_branches_create__cannot_force_create_over_current_branch(void)
8488 git_reference_free (branch2 );
8589}
8690
91+ void test_refs_branches_create__can_force_create_over_current_branch_in_bare_repo (void )
92+ {
93+ const git_oid * oid ;
94+ git_reference * branch2 ;
95+ retrieve_known_commit (& target , repo );
96+
97+ cl_git_pass (git_branch_lookup (& branch2 , repo , "master" , GIT_BRANCH_LOCAL ));
98+ cl_assert_equal_s ("refs/heads/master" , git_reference_name (branch2 ));
99+ cl_assert_equal_i (true, git_branch_is_head (branch2 ));
100+ oid = git_commit_id (target );
101+
102+ cl_git_pass (git_branch_create (& branch , repo , "master" , target , 1 ));
103+ git_reference_free (branch );
104+ branch = NULL ;
105+ cl_git_pass (git_branch_lookup (& branch , repo , "master" , GIT_BRANCH_LOCAL ));
106+ cl_assert_equal_s ("refs/heads/master" , git_reference_name (branch ));
107+ cl_git_pass (git_oid_cmp (git_reference_target (branch ), oid ));
108+ git_reference_free (branch2 );
109+ }
110+
87111void test_refs_branches_create__creating_a_branch_with_an_invalid_name_returns_EINVALIDSPEC (void )
88112{
89113 retrieve_known_commit (& target , repo );
0 commit comments