@@ -235,3 +235,55 @@ void test_reset_hard__reflog_is_correct(void)
235
235
git_annotated_commit_free (annotated );
236
236
237
237
}
238
+
239
+ void test_reset_hard__switch_file_to_dir (void )
240
+ {
241
+ git_index_entry entry = { 0 };
242
+ git_index * idx ;
243
+ git_object * commit ;
244
+ git_tree * tree ;
245
+ git_signature * sig ;
246
+ git_oid src_tree_id , tgt_tree_id ;
247
+ git_oid src_id , tgt_id ;
248
+
249
+ entry .mode = GIT_FILEMODE_BLOB ;
250
+ cl_git_pass (git_oid_fromstr (& entry .id , "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391" ));
251
+ cl_git_pass (git_index_new (& idx ));
252
+ cl_git_pass (git_signature_now (& sig , "foo" , "bar" ));
253
+
254
+ /* Create the old tree */
255
+ entry .path = "README" ;
256
+ cl_git_pass (git_index_add (idx , & entry ));
257
+ entry .path = "dir" ;
258
+ cl_git_pass (git_index_add (idx , & entry ));
259
+
260
+ cl_git_pass (git_index_write_tree_to (& src_tree_id , idx , repo ));
261
+ cl_git_pass (git_index_clear (idx ));
262
+
263
+ cl_git_pass (git_tree_lookup (& tree , repo , & src_tree_id ));
264
+ cl_git_pass (git_commit_create (& src_id , repo , NULL , sig , sig , NULL , "foo" , tree , 0 , NULL ));
265
+ git_tree_free (tree );
266
+
267
+ /* Create the new tree */
268
+ entry .path = "README" ;
269
+ cl_git_pass (git_index_add (idx , & entry ));
270
+ entry .path = "dir/FILE" ;
271
+ cl_git_pass (git_index_add (idx , & entry ));
272
+
273
+ cl_git_pass (git_index_write_tree_to (& tgt_tree_id , idx , repo ));
274
+ cl_git_pass (git_tree_lookup (& tree , repo , & tgt_tree_id ));
275
+ cl_git_pass (git_commit_create (& tgt_id , repo , NULL , sig , sig , NULL , "foo" , tree , 0 , NULL ));
276
+ git_tree_free (tree );
277
+ git_index_free (idx );
278
+ git_signature_free (sig );
279
+
280
+ /* Let's go to a known state of the src commit with the file named 'dir' */
281
+ cl_git_pass (git_object_lookup (& commit , repo , & src_id , GIT_OBJ_COMMIT ));
282
+ cl_git_pass (git_reset (repo , commit , GIT_RESET_HARD , NULL ));
283
+ git_object_free (commit );
284
+
285
+ /* And now we move over to the commit with the directory named 'dir' */
286
+ cl_git_pass (git_object_lookup (& commit , repo , & tgt_id , GIT_OBJ_COMMIT ));
287
+ cl_git_pass (git_reset (repo , commit , GIT_RESET_HARD , NULL ));
288
+ git_object_free (commit );
289
+ }
0 commit comments