@@ -44,6 +44,7 @@ struct checkout_opts {
44
44
int ignore_skipworktree ;
45
45
int ignore_other_worktrees ;
46
46
int show_progress ;
47
+ int overlay_mode ;
47
48
/*
48
49
* If new checkout options are added, skip_merge_working_tree
49
50
* should be updated accordingly.
@@ -132,14 +133,17 @@ static int skip_same_name(const struct cache_entry *ce, int pos)
132
133
return pos ;
133
134
}
134
135
135
- static int check_stage (int stage , const struct cache_entry * ce , int pos )
136
+ static int check_stage (int stage , const struct cache_entry * ce , int pos ,
137
+ int overlay_mode )
136
138
{
137
139
while (pos < active_nr &&
138
140
!strcmp (active_cache [pos ]-> name , ce -> name )) {
139
141
if (ce_stage (active_cache [pos ]) == stage )
140
142
return 0 ;
141
143
pos ++ ;
142
144
}
145
+ if (!overlay_mode )
146
+ return 0 ;
143
147
if (stage == 2 )
144
148
return error (_ ("path '%s' does not have our version" ), ce -> name );
145
149
else
@@ -165,14 +169,18 @@ static int check_stages(unsigned stages, const struct cache_entry *ce, int pos)
165
169
}
166
170
167
171
static int checkout_stage (int stage , const struct cache_entry * ce , int pos ,
168
- const struct checkout * state )
172
+ const struct checkout * state , int overlay_mode )
169
173
{
170
174
while (pos < active_nr &&
171
175
!strcmp (active_cache [pos ]-> name , ce -> name )) {
172
176
if (ce_stage (active_cache [pos ]) == stage )
173
177
return checkout_entry (active_cache [pos ], state , NULL );
174
178
pos ++ ;
175
179
}
180
+ if (!overlay_mode ) {
181
+ unlink_entry (ce );
182
+ return 0 ;
183
+ }
176
184
if (stage == 2 )
177
185
return error (_ ("path '%s' does not have our version" ), ce -> name );
178
186
else
@@ -247,9 +255,9 @@ static int checkout_merged(int pos, const struct checkout *state)
247
255
return status ;
248
256
}
249
257
250
- static void mark_ce_for_checkout (struct cache_entry * ce ,
251
- char * ps_matched ,
252
- const struct checkout_opts * opts )
258
+ static void mark_ce_for_checkout_overlay (struct cache_entry * ce ,
259
+ char * ps_matched ,
260
+ const struct checkout_opts * opts )
253
261
{
254
262
ce -> ce_flags &= ~CE_MATCHED ;
255
263
if (!opts -> ignore_skipworktree && ce_skip_worktree (ce ))
@@ -281,6 +289,25 @@ static void mark_ce_for_checkout(struct cache_entry *ce,
281
289
ce -> ce_flags |= CE_MATCHED ;
282
290
}
283
291
292
+ static void mark_ce_for_checkout_no_overlay (struct cache_entry * ce ,
293
+ char * ps_matched ,
294
+ const struct checkout_opts * opts )
295
+ {
296
+ ce -> ce_flags &= ~CE_MATCHED ;
297
+ if (!opts -> ignore_skipworktree && ce_skip_worktree (ce ))
298
+ return ;
299
+ if (ce_path_match (& the_index , ce , & opts -> pathspec , ps_matched )) {
300
+ ce -> ce_flags |= CE_MATCHED ;
301
+ if (opts -> source_tree && !(ce -> ce_flags & CE_UPDATE ))
302
+ /*
303
+ * In overlay mode, but the path is not in
304
+ * tree-ish, which means we should remove it
305
+ * from the index and the working tree.
306
+ */
307
+ ce -> ce_flags |= CE_REMOVE | CE_WT_REMOVE ;
308
+ }
309
+ }
310
+
284
311
static int checkout_paths (const struct checkout_opts * opts ,
285
312
const char * revision )
286
313
{
@@ -332,7 +359,14 @@ static int checkout_paths(const struct checkout_opts *opts,
332
359
* to be checked out.
333
360
*/
334
361
for (pos = 0 ; pos < active_nr ; pos ++ )
335
- mark_ce_for_checkout (active_cache [pos ], ps_matched , opts );
362
+ if (opts -> overlay_mode )
363
+ mark_ce_for_checkout_overlay (active_cache [pos ],
364
+ ps_matched ,
365
+ opts );
366
+ else
367
+ mark_ce_for_checkout_no_overlay (active_cache [pos ],
368
+ ps_matched ,
369
+ opts );
336
370
337
371
if (report_path_error (ps_matched , & opts -> pathspec , opts -> prefix )) {
338
372
free (ps_matched );
@@ -353,7 +387,7 @@ static int checkout_paths(const struct checkout_opts *opts,
353
387
if (opts -> force ) {
354
388
warning (_ ("path '%s' is unmerged" ), ce -> name );
355
389
} else if (opts -> writeout_stage ) {
356
- errs |= check_stage (opts -> writeout_stage , ce , pos );
390
+ errs |= check_stage (opts -> writeout_stage , ce , pos , opts -> overlay_mode );
357
391
} else if (opts -> merge ) {
358
392
errs |= check_stages ((1 <<2 ) | (1 <<3 ), ce , pos );
359
393
} else {
@@ -380,12 +414,14 @@ static int checkout_paths(const struct checkout_opts *opts,
380
414
continue ;
381
415
}
382
416
if (opts -> writeout_stage )
383
- errs |= checkout_stage (opts -> writeout_stage , ce , pos , & state );
417
+ errs |= checkout_stage (opts -> writeout_stage , ce , pos , & state , opts -> overlay_mode );
384
418
else if (opts -> merge )
385
419
errs |= checkout_merged (pos , & state );
386
420
pos = skip_same_name (ce , pos ) - 1 ;
387
421
}
388
422
}
423
+ remove_marked_cache_entries (& the_index , 1 );
424
+ remove_scheduled_dirs ();
389
425
errs |= finish_delayed_checkout (& state );
390
426
391
427
if (write_locked_index (& the_index , & lock_file , COMMIT_LOCK ))
@@ -547,6 +583,11 @@ static int skip_merge_working_tree(const struct checkout_opts *opts,
547
583
* opts->show_progress only impacts output so doesn't require a merge
548
584
*/
549
585
586
+ /*
587
+ * opts->overlay_mode cannot be used with switching branches so is
588
+ * not tested here
589
+ */
590
+
550
591
/*
551
592
* If we aren't creating a new branch any changes or updates will
552
593
* happen in the existing branch. Since that could only be updating
@@ -1183,6 +1224,10 @@ static int checkout_branch(struct checkout_opts *opts,
1183
1224
die (_ ("'%s' cannot be used with switching branches" ),
1184
1225
"--patch" );
1185
1226
1227
+ if (!opts -> overlay_mode )
1228
+ die (_ ("'%s' cannot be used with switching branches" ),
1229
+ "--no-overlay" );
1230
+
1186
1231
if (opts -> writeout_stage )
1187
1232
die (_ ("'%s' cannot be used with switching branches" ),
1188
1233
"--ours/--theirs" );
@@ -1271,6 +1316,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
1271
1316
"checkout" , "control recursive updating of submodules" ,
1272
1317
PARSE_OPT_OPTARG , option_parse_recurse_submodules_worktree_updater },
1273
1318
OPT_BOOL (0 , "progress" , & opts .show_progress , N_ ("force progress reporting" )),
1319
+ OPT_BOOL (0 , "overlay" , & opts .overlay_mode , N_ ("use overlay mode (default)" )),
1274
1320
OPT_END (),
1275
1321
};
1276
1322
@@ -1279,6 +1325,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
1279
1325
opts .overwrite_ignore = 1 ;
1280
1326
opts .prefix = prefix ;
1281
1327
opts .show_progress = -1 ;
1328
+ opts .overlay_mode = -1 ;
1282
1329
1283
1330
git_config (git_checkout_config , & opts );
1284
1331
@@ -1302,6 +1349,9 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
1302
1349
if ((!!opts .new_branch + !!opts .new_branch_force + !!opts .new_orphan_branch ) > 1 )
1303
1350
die (_ ("-b, -B and --orphan are mutually exclusive" ));
1304
1351
1352
+ if (opts .overlay_mode == 1 && opts .patch_mode )
1353
+ die (_ ("-p and --overlay are mutually exclusive" ));
1354
+
1305
1355
/*
1306
1356
* From here on, new_branch will contain the branch to be checked out,
1307
1357
* and new_branch_force and new_orphan_branch will tell us which one of
0 commit comments