@@ -91,24 +91,18 @@ void test_checkout_index__can_remove_untracked_files(void)
9191
9292void test_checkout_index__can_disable_pathspec_match (void )
9393{
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-
9994 char * files_to_checkout [] = { "test10.txt" , "test11.txt" };
100- size_t files_to_checkout_size = 2 ;
95+ git_checkout_options opts = GIT_CHECKOUT_OPTIONS_INIT ;
96+ git_object * objects ;
97+ git_index * index ;
10198
10299 /* reset to beginning of history (i.e. just a README file) */
103- g_opts .checkout_strategy =
104- GIT_CHECKOUT_FORCE | GIT_CHECKOUT_REMOVE_UNTRACKED ;
100+ opts .checkout_strategy = GIT_CHECKOUT_FORCE | GIT_CHECKOUT_REMOVE_UNTRACKED ;
105101
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 ;
102+ cl_git_pass (git_revparse_single (& objects , g_repo , "8496071c1b46c854b31185ea97743be6a8774479" ));
103+ cl_git_pass (git_checkout_tree (g_repo , objects , & opts ));
104+ cl_git_pass (git_repository_set_head_detached (g_repo , git_object_id (objects )));
105+ git_object_free (objects );
112106
113107 cl_git_pass (git_repository_index (& index , g_repo ));
114108
@@ -124,7 +118,7 @@ void test_checkout_index__can_disable_pathspec_match(void)
124118 cl_git_pass (git_index_add_bypath (index , "test12.txt" ));
125119 cl_git_pass (git_index_write (index ));
126120
127- cl_repo_commit_from_index (& commit_id , g_repo , NULL , 0 , "commit our test files" );
121+ cl_repo_commit_from_index (NULL , g_repo , NULL , 0 , "commit our test files" );
128122
129123 /* We modify the content of all 4 of our files */
130124 cl_git_rewritefile ("testrepo/test9.txt" , "modified\n" );
@@ -133,19 +127,21 @@ void test_checkout_index__can_disable_pathspec_match(void)
133127 cl_git_rewritefile ("testrepo/test12.txt" , "modified\n" );
134128
135129 /* We checkout only test10.txt and test11.txt */
136- g_opts .checkout_strategy =
130+ opts .checkout_strategy =
137131 GIT_CHECKOUT_FORCE |
138132 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 ));
133+ opts .paths .strings = files_to_checkout ;
134+ opts .paths .count = ARRAY_SIZE ( files_to_checkout ) ;
135+ cl_git_pass (git_checkout_index (g_repo , NULL , & opts ));
142136
143137 /* The only files that have been reverted to their original content
144138 should be test10.txt and test11.txt */
145139 check_file_contents ("testrepo/test9.txt" , "modified\n" );
146140 check_file_contents ("testrepo/test10.txt" , "original\n" );
147141 check_file_contents ("testrepo/test11.txt" , "original\n" );
148142 check_file_contents ("testrepo/test12.txt" , "modified\n" );
143+
144+ git_index_free (index );
149145}
150146
151147void test_checkout_index__honor_the_specified_pathspecs (void )
0 commit comments