]> git.ipfire.org Git - thirdparty/git.git/commitdiff
checkout: introduce checkout.overlayMode config
authorThomas Gummerer <t.gummerer@gmail.com>
Tue, 8 Jan 2019 21:52:25 +0000 (21:52 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 8 Jan 2019 22:49:28 +0000 (14:49 -0800)
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>
Documentation/config/checkout.txt
builtin/checkout.c
t/t2025-checkout-no-overlay.sh

index c4118fa1968711c9f5e6c491913a63c86d5ea20c..73380a8d862d37f2df65b5b9ff667f72392165aa 100644 (file)
@@ -21,3 +21,10 @@ checkout.optimizeNewBranch::
        will not update the skip-worktree bit in the index nor add/remove
        files in the working directory to reflect the current sparse checkout
        settings nor will it show the local changes.
+
+checkout.overlayMode::
+       In the default overlay mode, `git checkout` never
+       removes files from the index or the working tree.  When
+       setting `checkout.overlayMode` to false, files that appear in
+       the index and working tree, but not in <tree-ish> are removed,
+       to make them match <tree-ish> exactly.
index 0c5fe948ef58901870949532b1a4bfc2b1870452..b5dfc45736e45863f7ed798eca817212547e26b5 100644 (file)
@@ -1019,13 +1019,19 @@ static int switch_branches(const struct checkout_opts *opts,
 
 static int git_checkout_config(const char *var, const char *value, void *cb)
 {
+       struct checkout_opts *opts = cb;
+
        if (!strcmp(var, "checkout.optimizenewbranch")) {
                checkout_optimize_new_branch = git_config_bool(var, value);
                return 0;
        }
 
+       if (!strcmp(var, "checkout.overlaymode")) {
+               opts->overlay_mode = git_config_bool(var, value);
+               return 0;
+       }
+
        if (!strcmp(var, "diff.ignoresubmodules")) {
-               struct checkout_opts *opts = cb;
                handle_ignore_submodules_arg(&opts->diff_options, value);
                return 0;
        }
index 76330cb5ab79ab0ddfd97e0c06a8f4fb3a74d6c6..a4912e35cbe3aad886b99859100c762ac0a974af 100755 (executable)
@@ -44,4 +44,14 @@ test_expect_success '--no-overlay --theirs with D/F conflict deletes file' '
        test_path_is_missing file1
 '
 
+test_expect_success 'checkout with checkout.overlayMode=false deletes files not in <tree-ish>' '
+       >file &&
+       mkdir dir &&
+       >dir/file1 &&
+       git add file dir/file1 &&
+       git -c checkout.overlayMode=false checkout HEAD -- file &&
+       test_path_is_missing file &&
+       test_path_is_file dir/file1
+'
+
 test_done