@@ -51,6 +51,66 @@ void test_commit_commit__create_unexisting_update_ref(void)
5151 git_reference_free (ref );
5252}
5353
54+ void test_commit_commit__create_initial_commit (void )
55+ {
56+ git_oid oid ;
57+ git_tree * tree ;
58+ git_commit * commit ;
59+ git_signature * s ;
60+ git_reference * ref ;
61+
62+ git_oid_fromstr (& oid , "a65fedf39aefe402d3bb6e24df4d4f5fe4547750" );
63+ cl_git_pass (git_commit_lookup (& commit , _repo , & oid ));
64+
65+ git_oid_fromstr (& oid , "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162" );
66+ cl_git_pass (git_tree_lookup (& tree , _repo , & oid ));
67+
68+ cl_git_pass (git_signature_now (& s , "alice" , "alice@example.com" ));
69+
70+ cl_git_fail (git_reference_lookup (& ref , _repo , "refs/heads/foo/bar" ));
71+ cl_git_pass (git_commit_create (& oid , _repo , "refs/heads/foo/bar" , s , s ,
72+ NULL , "initial commit" , tree , 0 , NULL ));
73+
74+ cl_git_pass (git_reference_lookup (& ref , _repo , "refs/heads/foo/bar" ));
75+
76+ cl_assert_equal_oid (& oid , git_reference_target (ref ));
77+
78+ git_tree_free (tree );
79+ git_commit_free (commit );
80+ git_signature_free (s );
81+ git_reference_free (ref );
82+ }
83+
84+ void test_commit_commit__create_initial_commit_parent_not_current (void )
85+ {
86+ git_oid oid ;
87+ git_oid original_oid ;
88+ git_tree * tree ;
89+ git_commit * commit ;
90+ git_signature * s ;
91+
92+ git_oid_fromstr (& oid , "a65fedf39aefe402d3bb6e24df4d4f5fe4547750" );
93+ cl_git_pass (git_commit_lookup (& commit , _repo , & oid ));
94+
95+ git_oid_fromstr (& oid , "944c0f6e4dfa41595e6eb3ceecdb14f50fe18162" );
96+ cl_git_pass (git_tree_lookup (& tree , _repo , & oid ));
97+
98+ cl_git_pass (git_signature_now (& s , "alice" , "alice@example.com" ));
99+
100+ cl_git_pass (git_reference_name_to_id (& original_oid , _repo , "HEAD" ));
101+
102+ cl_git_fail (git_commit_create (& oid , _repo , "HEAD" , s , s ,
103+ NULL , "initial commit" , tree , 0 , NULL ));
104+
105+ cl_git_pass (git_reference_name_to_id (& oid , _repo , "HEAD" ));
106+
107+ cl_assert_equal_oid (& oid , & original_oid );
108+
109+ git_tree_free (tree );
110+ git_commit_free (commit );
111+ git_signature_free (s );
112+ }
113+
54114void assert_commit_summary (const char * expected , const char * given )
55115{
56116 git_commit * dummy ;
0 commit comments