Skip to content

Commit 1495ff7

Browse files
tgummerergitster
authored andcommitted
checkout: introduce checkout.overlayMode config
In the previous patch we introduced a new no-overlay mode for git checkout. Some users (such as the author of this commit) may want to have this mode turned on by default as it matches their mental model more closely. Make that possible by introducing a new config option to that extend. Signed-off-by: Thomas Gummerer <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 091e04b commit 1495ff7

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

Documentation/config/checkout.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,10 @@ checkout.optimizeNewBranch::
2121
will not update the skip-worktree bit in the index nor add/remove
2222
files in the working directory to reflect the current sparse checkout
2323
settings nor will it show the local changes.
24+
25+
checkout.overlayMode::
26+
In the default overlay mode, `git checkout` never
27+
removes files from the index or the working tree. When
28+
setting `checkout.overlayMode` to false, files that appear in
29+
the index and working tree, but not in <tree-ish> are removed,
30+
to make them match <tree-ish> exactly.

builtin/checkout.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,13 +1019,19 @@ static int switch_branches(const struct checkout_opts *opts,
10191019

10201020
static int git_checkout_config(const char *var, const char *value, void *cb)
10211021
{
1022+
struct checkout_opts *opts = cb;
1023+
10221024
if (!strcmp(var, "checkout.optimizenewbranch")) {
10231025
checkout_optimize_new_branch = git_config_bool(var, value);
10241026
return 0;
10251027
}
10261028

1029+
if (!strcmp(var, "checkout.overlaymode")) {
1030+
opts->overlay_mode = git_config_bool(var, value);
1031+
return 0;
1032+
}
1033+
10271034
if (!strcmp(var, "diff.ignoresubmodules")) {
1028-
struct checkout_opts *opts = cb;
10291035
handle_ignore_submodules_arg(&opts->diff_options, value);
10301036
return 0;
10311037
}

t/t2025-checkout-no-overlay.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,14 @@ test_expect_success '--no-overlay --theirs with D/F conflict deletes file' '
4444
test_path_is_missing file1
4545
'
4646

47+
test_expect_success 'checkout with checkout.overlayMode=false deletes files not in <tree-ish>' '
48+
>file &&
49+
mkdir dir &&
50+
>dir/file1 &&
51+
git add file dir/file1 &&
52+
git -c checkout.overlayMode=false checkout HEAD -- file &&
53+
test_path_is_missing file &&
54+
test_path_is_file dir/file1
55+
'
56+
4757
test_done

0 commit comments

Comments
 (0)