@@ -515,6 +515,7 @@ void test_checkout_index__target_directory(void)
515
515
516
516
opts .checkout_strategy = GIT_CHECKOUT_SAFE_CREATE ;
517
517
opts .target_directory = "alternative" ;
518
+ cl_assert (!git_path_isdir ("alternative" ));
518
519
519
520
opts .notify_flags = GIT_CHECKOUT_NOTIFY_ALL ;
520
521
opts .notify_cb = checkout_count_callback ;
@@ -533,4 +534,74 @@ void test_checkout_index__target_directory(void)
533
534
check_file_contents ("./alternative/README" , "hey there\n" );
534
535
check_file_contents ("./alternative/branch_file.txt" , "hi\nbye!\n" );
535
536
check_file_contents ("./alternative/new.txt" , "my new file\n" );
537
+
538
+ cl_git_pass (git_futils_rmdir_r (
539
+ "alternative" , NULL , GIT_RMDIR_REMOVE_FILES ));
540
+ }
541
+
542
+ void test_checkout_index__target_directory_from_bare (void )
543
+ {
544
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT ;
545
+ git_index * index ;
546
+ git_object * head = NULL ;
547
+ checkout_counts cts ;
548
+ memset (& cts , 0 , sizeof (cts ));
549
+
550
+ test_checkout_index__cleanup ();
551
+
552
+ g_repo = cl_git_sandbox_init ("testrepo.git" );
553
+ cl_assert (git_repository_is_bare (g_repo ));
554
+
555
+ cl_git_pass (git_repository_index (& index , g_repo ));
556
+ cl_git_pass (git_revparse_single (& head , g_repo , "HEAD^{tree}" ));
557
+ cl_git_pass (git_index_read_tree (index , (const git_tree * )head ));
558
+ cl_git_pass (git_index_write (index ));
559
+ git_index_free (index );
560
+
561
+ opts .checkout_strategy = GIT_CHECKOUT_SAFE_CREATE ;
562
+
563
+ opts .notify_flags = GIT_CHECKOUT_NOTIFY_ALL ;
564
+ opts .notify_cb = checkout_count_callback ;
565
+ opts .notify_payload = & cts ;
566
+
567
+ /* fail to checkout a bare repo */
568
+ cl_git_fail (git_checkout_index (g_repo , NULL , & opts ));
569
+
570
+ opts .target_directory = "alternative" ;
571
+ cl_assert (!git_path_isdir ("alternative" ));
572
+
573
+ cl_git_pass (git_checkout_index (g_repo , NULL , & opts ));
574
+
575
+ cl_assert_equal_i (0 , cts .n_untracked );
576
+ cl_assert_equal_i (0 , cts .n_ignored );
577
+ cl_assert_equal_i (3 , cts .n_updates );
578
+
579
+ check_file_contents ("./alternative/README" , "hey there\n" );
580
+ check_file_contents ("./alternative/branch_file.txt" , "hi\nbye!\n" );
581
+ check_file_contents ("./alternative/new.txt" , "my new file\n" );
582
+
583
+ cl_git_pass (git_futils_rmdir_r (
584
+ "alternative" , NULL , GIT_RMDIR_REMOVE_FILES ));
585
+ }
586
+
587
+ void test_checkout_index__can_get_repo_from_index (void )
588
+ {
589
+ git_index * index ;
590
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT ;
591
+
592
+ cl_assert_equal_i (false, git_path_isfile ("./testrepo/README" ));
593
+ cl_assert_equal_i (false, git_path_isfile ("./testrepo/branch_file.txt" ));
594
+ cl_assert_equal_i (false, git_path_isfile ("./testrepo/new.txt" ));
595
+
596
+ opts .checkout_strategy = GIT_CHECKOUT_SAFE_CREATE ;
597
+
598
+ cl_git_pass (git_repository_index (& index , g_repo ));
599
+
600
+ cl_git_pass (git_checkout_index (NULL , index , & opts ));
601
+
602
+ check_file_contents ("./testrepo/README" , "hey there\n" );
603
+ check_file_contents ("./testrepo/branch_file.txt" , "hi\nbye!\n" );
604
+ check_file_contents ("./testrepo/new.txt" , "my new file\n" );
605
+
606
+ git_index_free (index );
536
607
}
0 commit comments