7
7
#define USE_THE_INDEX_COMPATIBILITY_MACROS
8
8
#include "builtin.h"
9
9
#include "config.h"
10
+ #include "dir.h"
10
11
#include "lockfile.h"
11
12
#include "quote.h"
12
13
#include "cache-tree.h"
@@ -65,6 +66,7 @@ static int checkout_file(const char *name, const char *prefix)
65
66
int namelen = strlen (name );
66
67
int pos = cache_name_pos (name , namelen );
67
68
int has_same_name = 0 ;
69
+ int is_file = 0 ;
68
70
int did_checkout = 0 ;
69
71
int errs = 0 ;
70
72
@@ -78,6 +80,9 @@ static int checkout_file(const char *name, const char *prefix)
78
80
break ;
79
81
has_same_name = 1 ;
80
82
pos ++ ;
83
+ if (S_ISSPARSEDIR (ce -> ce_mode ))
84
+ break ;
85
+ is_file = 1 ;
81
86
if (ce_stage (ce ) != checkout_stage
82
87
&& (CHECKOUT_ALL != checkout_stage || !ce_stage (ce )))
83
88
continue ;
@@ -106,6 +111,8 @@ static int checkout_file(const char *name, const char *prefix)
106
111
fprintf (stderr , "git checkout-index: %s " , name );
107
112
if (!has_same_name )
108
113
fprintf (stderr , "is not in the cache" );
114
+ else if (!is_file )
115
+ fprintf (stderr , "is a sparse directory" );
109
116
else if (checkout_stage )
110
117
fprintf (stderr , "does not exist at stage %d" ,
111
118
checkout_stage );
@@ -116,15 +123,18 @@ static int checkout_file(const char *name, const char *prefix)
116
123
return -1 ;
117
124
}
118
125
119
- static int checkout_all (const char * prefix , int prefix_length )
126
+ static int checkout_all (const char * prefix , int prefix_length , int include_sparse )
120
127
{
121
128
int i , errs = 0 ;
122
129
struct cache_entry * last_ce = NULL ;
123
130
124
- /* TODO: audit for interaction with sparse-index. */
125
- ensure_full_index (& the_index );
131
+ if (include_sparse )
132
+ ensure_full_index (& the_index );
133
+
126
134
for (i = 0 ; i < active_nr ; i ++ ) {
127
135
struct cache_entry * ce = active_cache [i ];
136
+ if (!include_sparse && !path_in_sparse_checkout (ce -> name , & the_index ))
137
+ continue ;
128
138
if (ce_stage (ce ) != checkout_stage
129
139
&& (CHECKOUT_ALL != checkout_stage || !ce_stage (ce )))
130
140
continue ;
@@ -176,6 +186,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
176
186
int i ;
177
187
struct lock_file lock_file = LOCK_INIT ;
178
188
int all = 0 ;
189
+ int include_sparse = 0 ;
179
190
int read_from_stdin = 0 ;
180
191
int prefix_length ;
181
192
int force = 0 , quiet = 0 , not_new = 0 ;
@@ -185,6 +196,8 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
185
196
struct option builtin_checkout_index_options [] = {
186
197
OPT_BOOL ('a' , "all" , & all ,
187
198
N_ ("check out all files in the index" )),
199
+ OPT_BOOL (0 , "sparse" , & include_sparse ,
200
+ N_ ("do not skip files outside the sparse checkout boundary" )),
188
201
OPT__FORCE (& force , N_ ("force overwrite of existing files" ), 0 ),
189
202
OPT__QUIET (& quiet ,
190
203
N_ ("no warning for existing files and files not in index" )),
@@ -212,6 +225,9 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
212
225
git_config (git_default_config , NULL );
213
226
prefix_length = prefix ? strlen (prefix ) : 0 ;
214
227
228
+ prepare_repo_settings (the_repository );
229
+ the_repository -> settings .command_requires_full_index = 0 ;
230
+
215
231
if (read_cache () < 0 ) {
216
232
die ("invalid cache" );
217
233
}
@@ -247,6 +263,8 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
247
263
248
264
if (all )
249
265
die ("git checkout-index: don't mix '--all' and explicit filenames" );
266
+ if (include_sparse )
267
+ die ("git checkout-index: don't mix '--sparse' and explicit filenames" );
250
268
if (read_from_stdin )
251
269
die ("git checkout-index: don't mix '--stdin' and explicit filenames" );
252
270
p = prefix_path (prefix , prefix_length , arg );
@@ -280,7 +298,7 @@ int cmd_checkout_index(int argc, const char **argv, const char *prefix)
280
298
}
281
299
282
300
if (all )
283
- err |= checkout_all (prefix , prefix_length );
301
+ err |= checkout_all (prefix , prefix_length , include_sparse );
284
302
285
303
if (pc_workers > 1 )
286
304
err |= run_parallel_checkout (& state , pc_workers , pc_threshold ,
0 commit comments