Message ID | 20181220134820.21810-9-t.gummerer@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | introduce no-overlay mode in git checkout | expand |
Thomas Gummerer <t.gummerer@gmail.com> writes: > 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> > --- > Documentation/config/checkout.txt | 7 +++++++ > builtin/checkout.c | 8 +++++++- > t/t2025-checkout-no-overlay.sh | 10 ++++++++++ > 3 files changed, 24 insertions(+), 1 deletion(-) > > diff --git a/Documentation/config/checkout.txt b/Documentation/config/checkout.txt > index c4118fa196..53f917e15e 100644 > --- a/Documentation/config/checkout.txt > +++ b/Documentation/config/checkout.txt > @@ -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 files `git checkout` never > + removes files from the index or the working tree. Technically the above "never removes" is incorrect. $ mv COPYING 1 && mkdir COPYING && mv 1 COPYING/COPYING $ git add COPYING $ git checkout HEAD COPYING would remove COPYING/1 from the index and from the working tree to make room. Because I think that a bit of white lie like what you wrote would help readers understand the key point of "overlay or not overlay" better than an overly precise description of the reason why the removal in the above three-liner case is the right thing to do, I think the text in the patch is good enough at least for now, but I'd mention it in case somebody else can think of a better phrasing to covey the same key point without being technically incorrect. Thanks.
On 01/02, Junio C Hamano wrote: > Thomas Gummerer <t.gummerer@gmail.com> writes: > > > 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> > > --- > > Documentation/config/checkout.txt | 7 +++++++ > > builtin/checkout.c | 8 +++++++- > > t/t2025-checkout-no-overlay.sh | 10 ++++++++++ > > 3 files changed, 24 insertions(+), 1 deletion(-) > > > > diff --git a/Documentation/config/checkout.txt b/Documentation/config/checkout.txt > > index c4118fa196..53f917e15e 100644 > > --- a/Documentation/config/checkout.txt > > +++ b/Documentation/config/checkout.txt > > @@ -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 files `git checkout` never > > + removes files from the index or the working tree. > > Technically the above "never removes" is incorrect. > > $ mv COPYING 1 && mkdir COPYING && mv 1 COPYING/COPYING > $ git add COPYING > $ git checkout HEAD COPYING > > would remove COPYING/1 from the index and from the working tree to > make room. Right, that's a case I didn't think about. > Because I think that a bit of white lie like what you wrote would > help readers understand the key point of "overlay or not overlay" > better than an overly precise description of the reason why the > removal in the above three-liner case is the right thing to do, I > think the text in the patch is good enough at least for now, but I'd > mention it in case somebody else can think of a better phrasing to > covey the same key point without being technically incorrect. Maybe it would be enough to say "... `git checkout` never removes files, that are not in the tree being checked out, from the index or the working tree"? It is more technically correct, but dunno making the sentence harder to read is worth it. > Thanks.
Thomas Gummerer <t.gummerer@gmail.com> writes: > Maybe it would be enough to say "... `git checkout` never removes > files, that are not in the tree being checked out, from the index or > the working tree"? It is more technically correct, but dunno making > the sentence harder to read is worth it. Yeah, I share the same feeling. Let's say the text in the posted patch is good enough and move on. Thanks.
diff --git a/Documentation/config/checkout.txt b/Documentation/config/checkout.txt index c4118fa196..53f917e15e 100644 --- a/Documentation/config/checkout.txt +++ b/Documentation/config/checkout.txt @@ -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 files `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. diff --git a/builtin/checkout.c b/builtin/checkout.c index 0c5fe948ef..b5dfc45736 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -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; } diff --git a/t/t2025-checkout-no-overlay.sh b/t/t2025-checkout-no-overlay.sh index 76330cb5ab..a4912e35cb 100755 --- a/t/t2025-checkout-no-overlay.sh +++ b/t/t2025-checkout-no-overlay.sh @@ -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
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> --- Documentation/config/checkout.txt | 7 +++++++ builtin/checkout.c | 8 +++++++- t/t2025-checkout-no-overlay.sh | 10 ++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-)