@@ -38,7 +38,7 @@ void test_checkout_head__with_index_only_tree(void)
3838 cl_git_pass (git_repository_index (& index , g_repo ));
3939
4040 p_mkdir ("testrepo/newdir" , 0777 );
41- cl_git_mkfile ("testrepo/newdir/newfile.txt" , "new file\n" );
41+ cl_git_mkfile ("testrepo/newdir/newfile.txt" , "new file\n" );
4242
4343 cl_git_pass (git_index_add_bypath (index , "newdir/newfile.txt" ));
4444 cl_git_pass (git_index_write (index ));
@@ -60,3 +60,79 @@ void test_checkout_head__with_index_only_tree(void)
6060
6161 git_index_free (index );
6262}
63+
64+ void test_checkout_head__do_not_remove_untracked_file (void )
65+ {
66+ git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT ;
67+ git_index * index ;
68+
69+ cl_git_pass (p_mkdir ("testrepo/tracked" , 0755 ));
70+ cl_git_mkfile ("testrepo/tracked/tracked" , "tracked\n" );
71+ cl_git_mkfile ("testrepo/tracked/untracked" , "untracked\n" );
72+
73+ cl_git_pass (git_repository_index (& index , g_repo ));
74+ cl_git_pass (git_index_add_bypath (index , "tracked/tracked" ));
75+ cl_git_pass (git_index_write (index ));
76+
77+ git_index_free (index );
78+
79+ opts .checkout_strategy = GIT_CHECKOUT_FORCE ;
80+ cl_git_pass (git_checkout_head (g_repo , & opts ));
81+
82+ cl_assert (!git_path_isfile ("testrepo/tracked/tracked" ));
83+ cl_assert (git_path_isfile ("testrepo/tracked/untracked" ));
84+ }
85+
86+ void test_checkout_head__do_not_remove_untracked_file_in_subdir (void )
87+ {
88+ git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT ;
89+ git_index * index ;
90+
91+ cl_git_pass (p_mkdir ("testrepo/tracked" , 0755 ));
92+ cl_git_pass (p_mkdir ("testrepo/tracked/subdir" , 0755 ));
93+ cl_git_mkfile ("testrepo/tracked/tracked" , "tracked\n" );
94+ cl_git_mkfile ("testrepo/tracked/subdir/tracked" , "tracked\n" );
95+ cl_git_mkfile ("testrepo/tracked/subdir/untracked" , "untracked\n" );
96+
97+ cl_git_pass (git_repository_index (& index , g_repo ));
98+ cl_git_pass (git_index_add_bypath (index , "tracked/tracked" ));
99+ cl_git_pass (git_index_add_bypath (index , "tracked/subdir/tracked" ));
100+ cl_git_pass (git_index_write (index ));
101+
102+ git_index_free (index );
103+
104+ opts .checkout_strategy = GIT_CHECKOUT_FORCE ;
105+ cl_git_pass (git_checkout_head (g_repo , & opts ));
106+
107+ cl_assert (!git_path_isfile ("testrepo/tracked/tracked" ));
108+ cl_assert (!git_path_isfile ("testrepo/tracked/subdir/tracked" ));
109+ cl_assert (git_path_isfile ("testrepo/tracked/subdir/untracked" ));
110+ }
111+
112+ void test_checkout_head__do_remove_tracked_subdir (void )
113+ {
114+ git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT ;
115+ git_index * index ;
116+
117+ cl_git_pass (p_mkdir ("testrepo/subdir" , 0755 ));
118+ cl_git_pass (p_mkdir ("testrepo/subdir/tracked" , 0755 ));
119+ cl_git_mkfile ("testrepo/subdir/tracked-file" , "tracked\n" );
120+ cl_git_mkfile ("testrepo/subdir/untracked-file" , "untracked\n" );
121+ cl_git_mkfile ("testrepo/subdir/tracked/tracked1" , "tracked\n" );
122+ cl_git_mkfile ("testrepo/subdir/tracked/tracked2" , "tracked\n" );
123+
124+ cl_git_pass (git_repository_index (& index , g_repo ));
125+ cl_git_pass (git_index_add_bypath (index , "subdir/tracked-file" ));
126+ cl_git_pass (git_index_add_bypath (index , "subdir/tracked/tracked1" ));
127+ cl_git_pass (git_index_add_bypath (index , "subdir/tracked/tracked2" ));
128+ cl_git_pass (git_index_write (index ));
129+
130+ git_index_free (index );
131+
132+ opts .checkout_strategy = GIT_CHECKOUT_FORCE ;
133+ cl_git_pass (git_checkout_head (g_repo , & opts ));
134+
135+ cl_assert (!git_path_isdir ("testrepo/subdir/tracked" ));
136+ cl_assert (!git_path_isfile ("testrepo/subdir/tracked-file" ));
137+ cl_assert (git_path_isfile ("testrepo/subdir/untracked-file" ));
138+ }
0 commit comments