@@ -2544,6 +2544,17 @@ static int checkout_data_init(
25442544#define CHECKOUT_INDEX_DONT_WRITE_MASK \
25452545 (GIT_CHECKOUT_DONT_UPDATE_INDEX | GIT_CHECKOUT_DONT_WRITE_INDEX)
25462546
2547+ GIT_INLINE (void ) setup_pathspecs (
2548+ git_iterator_options * iter_opts ,
2549+ const git_checkout_options * checkout_opts )
2550+ {
2551+ if (checkout_opts &&
2552+ (checkout_opts -> checkout_strategy & GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH )) {
2553+ iter_opts -> pathlist .count = checkout_opts -> paths .count ;
2554+ iter_opts -> pathlist .strings = checkout_opts -> paths .strings ;
2555+ }
2556+ }
2557+
25472558int git_checkout_iterator (
25482559 git_iterator * target ,
25492560 git_index * index ,
@@ -2586,6 +2597,8 @@ int git_checkout_iterator(
25862597 workdir_opts .start = data .pfx ;
25872598 workdir_opts .end = data .pfx ;
25882599
2600+ setup_pathspecs (& workdir_opts , opts );
2601+
25892602 if ((error = git_iterator_reset_range (target , data .pfx , data .pfx )) < 0 ||
25902603 (error = git_iterator_for_workdir_ext (
25912604 & workdir , data .repo , data .opts .target_directory , index , NULL ,
@@ -2596,10 +2609,8 @@ int git_checkout_iterator(
25962609 GIT_ITERATOR_IGNORE_CASE : GIT_ITERATOR_DONT_IGNORE_CASE ;
25972610 baseline_opts .start = data .pfx ;
25982611 baseline_opts .end = data .pfx ;
2599- if (opts && (opts -> checkout_strategy & GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH )) {
2600- baseline_opts .pathlist .count = opts -> paths .count ;
2601- baseline_opts .pathlist .strings = opts -> paths .strings ;
2602- }
2612+
2613+ setup_pathspecs (& baseline_opts , opts );
26032614
26042615 if (data .opts .baseline_index ) {
26052616 if ((error = git_iterator_for_index (
@@ -2689,6 +2700,7 @@ int git_checkout_index(
26892700 git_index * index ,
26902701 const git_checkout_options * opts )
26912702{
2703+ git_iterator_options iter_opts = GIT_ITERATOR_OPTIONS_INIT ;
26922704 int error , owned = 0 ;
26932705 git_iterator * index_i ;
26942706
@@ -2716,7 +2728,9 @@ int git_checkout_index(
27162728 return error ;
27172729 GIT_REFCOUNT_INC (index );
27182730
2719- if (!(error = git_iterator_for_index (& index_i , repo , index , NULL )))
2731+ setup_pathspecs (& iter_opts , opts );
2732+
2733+ if (!(error = git_iterator_for_index (& index_i , repo , index , & iter_opts )))
27202734 error = git_checkout_iterator (index_i , index , opts );
27212735
27222736 if (owned )
@@ -2773,10 +2787,7 @@ int git_checkout_tree(
27732787 if ((error = git_repository_index (& index , repo )) < 0 )
27742788 return error ;
27752789
2776- if (opts && (opts -> checkout_strategy & GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH )) {
2777- iter_opts .pathlist .count = opts -> paths .count ;
2778- iter_opts .pathlist .strings = opts -> paths .strings ;
2779- }
2790+ setup_pathspecs (& iter_opts , opts );
27802791
27812792 if (!(error = git_iterator_for_tree (& tree_i , tree , & iter_opts )))
27822793 error = git_checkout_iterator (tree_i , index , opts );
0 commit comments