44
int ignore_skipworktree;
45
int ignore_other_worktrees;
46
int show_progress;
47
+ int overlay_mode;
48
/*
49
* If new checkout options are added, skip_merge_working_tree
50
* should be updated accordingly.
133
return pos;
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)
138
{
139
while (pos < active_nr &&
140
!strcmp(active_cache[pos]->name, ce->name)) {
142
return 0;
143
pos++;
144
}
145
+ if (!overlay_mode)
146
+ return 0;
147
if (stage == 2)
148
return error(_("path '%s' does not have our version"), ce->name);
149
else
169
}
170
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)
173
{
174
while (pos < active_nr &&
175
!strcmp(active_cache[pos]->name, ce->name)) {
177
return checkout_entry(active_cache[pos], state, NULL);
178
pos++;
179
}
180
+ if (!overlay_mode) {
181
+ unlink_entry(ce);
182
+ return 0;
183
+ }
184
if (stage == 2)
185
return error(_("path '%s' does not have our version"), ce->name);
186
else
255
return status;
256
}
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)
261
{
262
ce->ce_flags &= ~CE_MATCHED;
263
if (!opts->ignore_skipworktree && ce_skip_worktree(ce))
289
ce->ce_flags |= CE_MATCHED;
290
}
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
+
311
static int checkout_paths(const struct checkout_opts *opts,
312
const char *revision)
313
{
359
* to be checked out.
360
*/
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);
370
371
if (report_path_error(ps_matched, &opts->pathspec, opts->prefix)) {
372
free(ps_matched);
387
if (opts->force) {
388
warning(_("path '%s' is unmerged"), ce->name);
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);
391
} else if (opts->merge) {
392
errs |= check_stages((1<<2) | (1<<3), ce, pos);
393
} else {
414
continue;
415
}
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);
418
else if (opts->merge)
419
errs |= checkout_merged(pos, &state);
420
pos = skip_same_name(ce, pos) - 1;
421
}
422
}
423
+ remove_marked_cache_entries(&the_index, 1);
424
+ remove_scheduled_dirs();
425
errs |= finish_delayed_checkout(&state);
426
427
if (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))
583
* opts->show_progress only impacts output so doesn't require a merge
584
*/
585
586
+ /*
587
+ * opts->overlay_mode cannot be used with switching branches so is
588
+ * not tested here
589
+ */
590
+
591
/*
592
* If we aren't creating a new branch any changes or updates will
593
* happen in the existing branch. Since that could only be updating
1224
die(_("'%s' cannot be used with switching branches"),
1225
"--patch");
1226
1227
+ if (!opts->overlay_mode)
1228
+ die(_("'%s' cannot be used with switching branches"),
1229
+ "--no-overlay");
1230
+
1231
if (opts->writeout_stage)
1232
die(_("'%s' cannot be used with switching branches"),
1233
"--ours/--theirs");
1316
"checkout", "control recursive updating of submodules",
1317
PARSE_OPT_OPTARG, option_parse_recurse_submodules_worktree_updater },
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)")),
1320
OPT_END(),
1321
};
1322
1325
opts.overwrite_ignore = 1;
1326
opts.prefix = prefix;
1327
opts.show_progress = -1;
1328
+ opts.overlay_mode = -1;
1329
1330
git_config(git_checkout_config, &opts);
1331
1349
if ((!!opts.new_branch + !!opts.new_branch_force + !!opts.new_orphan_branch) > 1)
1350
die(_("-b, -B and --orphan are mutually exclusive"));
1351
1352
+ if (opts.overlay_mode == 1 && opts.patch_mode)
1353
+ die(_("-p and --overlay are mutually exclusive"));
1354
+
1355
/*
1356
* From here on, new_branch will contain the branch to be checked out,
1357
* and new_branch_force and new_orphan_branch will tell us which one of