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 <t.gummerer@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Thomas Gummerer committed
Jan 8, 2019 at 21:52 UTC
1495ff7da526c61bff88e31fcdf419fb023a42c5
3 files changed
+24
-1
Documentation/config/checkout.txt
+7
@@ -21,3 +21,10 @@ checkout.optimizeNewBranch::
21
will not update the skip-worktree bit in the index nor add/remove
22
files in the working directory to reflect the current sparse checkout
23
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
+7
-1
@@ -1019,13 +1019,19 @@ static int switch_branches(const struct checkout_opts *opts,
1019
1020
static int git_checkout_config(const char *var, const char *value, void *cb)
1021
{
1022
+ struct checkout_opts *opts = cb;
1023
+
1024
if (!strcmp(var, "checkout.optimizenewbranch")) {
1025
checkout_optimize_new_branch = git_config_bool(var, value);
1026
return 0;
1027
}
1028
1029
+ if (!strcmp(var, "checkout.overlaymode")) {
1030
+ opts->overlay_mode = git_config_bool(var, value);
1031
+ return 0;
1032
+ }
1033
+
1034
if (!strcmp(var, "diff.ignoresubmodules")) {
1028
- struct checkout_opts *opts = cb;
1035
handle_ignore_submodules_arg(&opts->diff_options, value);
1036
return 0;
1037
}
t/t2025-checkout-no-overlay.sh
+10
@@ -44,4 +44,14 @@ test_expect_success '--no-overlay --theirs with D/F conflict deletes file' '
44
test_path_is_missing file1
45
'
46
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
+
57
test_done