@@ -89,6 +89,65 @@ void test_checkout_index__can_remove_untracked_files(void)
8989 cl_assert_equal_i (false, git_path_isdir ("./testrepo/dir" ));
9090}
9191
92+ void test_checkout_index__can_disable_pathspec_match (void )
93+ {
94+ static git_index * index ;
95+ git_oid commit_id ;
96+ git_checkout_options g_opts = GIT_CHECKOUT_OPTIONS_INIT ;
97+ git_object * g_object ;
98+
99+ char * files_to_checkout [] = { "test10.txt" , "test11.txt" };
100+ size_t files_to_checkout_size = 2 ;
101+
102+ /* reset to beginning of history (i.e. just a README file) */
103+ g_opts .checkout_strategy =
104+ GIT_CHECKOUT_FORCE | GIT_CHECKOUT_REMOVE_UNTRACKED ;
105+
106+ cl_git_pass (git_revparse_single (& g_object , g_repo , "8496071c1b46c854b31185ea97743be6a8774479" ));
107+ cl_git_pass (git_checkout_tree (g_repo , g_object , & g_opts ));
108+ cl_git_pass (
109+ git_repository_set_head_detached (g_repo , git_object_id (g_object )));
110+ git_object_free (g_object );
111+ g_object = NULL ;
112+
113+ cl_git_pass (git_repository_index (& index , g_repo ));
114+
115+ /* We create 4 files and commit them */
116+ cl_git_mkfile ("testrepo/test9.txt" , "original\n" );
117+ cl_git_mkfile ("testrepo/test10.txt" , "original\n" );
118+ cl_git_mkfile ("testrepo/test11.txt" , "original\n" );
119+ cl_git_mkfile ("testrepo/test12.txt" , "original\n" );
120+
121+ cl_git_pass (git_index_add_bypath (index , "test9.txt" ));
122+ cl_git_pass (git_index_add_bypath (index , "test10.txt" ));
123+ cl_git_pass (git_index_add_bypath (index , "test11.txt" ));
124+ cl_git_pass (git_index_add_bypath (index , "test12.txt" ));
125+ cl_git_pass (git_index_write (index ));
126+
127+ cl_repo_commit_from_index (& commit_id , g_repo , NULL , 0 , "commit our test files" );
128+
129+ /* We modify the content of all 4 of our files */
130+ cl_git_rewritefile ("testrepo/test9.txt" , "modified\n" );
131+ cl_git_rewritefile ("testrepo/test10.txt" , "modified\n" );
132+ cl_git_rewritefile ("testrepo/test11.txt" , "modified\n" );
133+ cl_git_rewritefile ("testrepo/test12.txt" , "modified\n" );
134+
135+ /* We checkout only test10.txt and test11.txt */
136+ g_opts .checkout_strategy =
137+ GIT_CHECKOUT_FORCE |
138+ GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH ;
139+ g_opts .paths .strings = files_to_checkout ;
140+ g_opts .paths .count = files_to_checkout_size ;
141+ cl_git_pass (git_checkout_index (g_repo , NULL , & g_opts ));
142+
143+ /* The only files that have been reverted to their original content
144+ should be test10.txt and test11.txt */
145+ check_file_contents ("testrepo/test9.txt" , "modified\n" );
146+ check_file_contents ("testrepo/test10.txt" , "original\n" );
147+ check_file_contents ("testrepo/test11.txt" , "original\n" );
148+ check_file_contents ("testrepo/test12.txt" , "modified\n" );
149+ }
150+
92151void test_checkout_index__honor_the_specified_pathspecs (void )
93152{
94153 git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT ;
0 commit comments