git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 8/8] checkout: introduce checkout.overlayMode config

From
Thomas Gummerer <t.gummerer@gmail.com>
Date
Jan 8, 2019, 21:52 UTC
Message-ID
<20190108215225.3077-9-t.gummerer@gmail.com>
In-Reply-To
<20190108215225.3077-1-t.gummerer@gmail.com>

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..73380a8d86 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, `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
-- 
2.20.1.153.gd81d796ee0
Previous: Philip Oakley
Message 115 of 115 in “introduce no-overlay and cached mode in git checkout”
  1. 0/8 introduce no-overlay and cached mode in git checkoutThomas Gummerer, Dec 9, 2018
  2. 1/8 move worktree tests to t24*Thomas Gummerer, Dec 9, 2018
  3. Junio C HamanoDec 10, 2018
  4. Duy NguyenDec 10, 2018
  5. Thomas GummererDec 11, 2018
  6. Eric SunshineDec 12, 2018
  7. Duy NguyenDec 12, 2018
  8. 3/8 entry: support CE_WT_REMOVE flag in checkout_entryThomas Gummerer, Dec 9, 2018
  9. Duy NguyenDec 10, 2018
  10. Junio C HamanoDec 11, 2018
  11. Duy NguyenDec 12, 2018
  12. Junio C HamanoDec 12, 2018
  13. Elijah NewrenDec 10, 2018
  14. Thomas GummererDec 11, 2018
  15. 2/8 entry: factor out unlink_entry functionThomas Gummerer, Dec 9, 2018
  16. Duy NguyenDec 10, 2018
  17. Elijah NewrenDec 10, 2018
  18. Duy NguyenDec 10, 2018
  19. Junio C HamanoDec 11, 2018
  20. Thomas GummererDec 20, 2018
  21. 4/8 read-cache: add invalidate parameter to remove_marked_cache_entriesThomas Gummerer, Dec 9, 2018
  22. Duy NguyenDec 10, 2018
  23. Elijah NewrenDec 10, 2018
  24. Duy NguyenDec 10, 2018
  25. Elijah NewrenDec 10, 2018
  26. Duy NguyenDec 10, 2018
  27. Elijah NewrenDec 10, 2018
  28. Thomas GummererDec 11, 2018
  29. Junio C HamanoDec 11, 2018
  30. 5/8 checkout: introduce --{,no-}overlay optionThomas Gummerer, Dec 9, 2018
  31. Duy NguyenDec 10, 2018
  32. Thomas GummererDec 11, 2018
  33. Elijah NewrenDec 10, 2018
  34. Junio C HamanoDec 11, 2018
  35. Elijah NewrenDec 11, 2018
  36. Thomas GummererDec 11, 2018
  37. 6/8 checkout: add --cached optionThomas Gummerer, Dec 9, 2018
  38. Duy NguyenDec 10, 2018
  39. Junio C HamanoDec 11, 2018
  40. Elijah NewrenDec 11, 2018
  41. Duy NguyenDec 11, 2018
  42. Duy NguyenJan 31, 2019
  43. Junio C HamanoJan 31, 2019
  44. Duy NguyenFeb 1, 2019
  45. Junio C HamanoFeb 1, 2019
  46. Duy NguyenFeb 2, 2019
  47. Duy NguyenFeb 19, 2019
  48. Elijah NewrenFeb 19, 2019
  49. Duy NguyenFeb 19, 2019
  50. Junio C HamanoFeb 19, 2019
  51. Elijah NewrenFeb 19, 2019
  52. Junio C HamanoFeb 19, 2019
  53. Elijah NewrenFeb 19, 2019
  54. Duy NguyenFeb 20, 2019
  55. Junio C HamanoFeb 19, 2019
  56. Junio C HamanoFeb 19, 2019
  57. Elijah NewrenFeb 19, 2019
  58. Junio C HamanoFeb 19, 2019
  59. Duy NguyenFeb 20, 2019
  60. Duy NguyenFeb 20, 2019
  61. Duy NguyenFeb 20, 2019
  62. Elijah NewrenFeb 19, 2019
  63. Junio C HamanoFeb 19, 2019
  64. Elijah NewrenDec 10, 2018
  65. Thomas GummererDec 11, 2018
  66. 7/8 checkout: allow ignoring unmatched pathspecThomas Gummerer, Dec 9, 2018
  67. Duy NguyenDec 10, 2018
  68. Thomas GummererDec 11, 2018
  69. Elijah NewrenDec 10, 2018
  70. Thomas GummererDec 11, 2018
  71. 8/8 stash: use git checkout --no-overlayThomas Gummerer, Dec 9, 2018
  72. Elijah NewrenDec 10, 2018
  73. Junio C HamanoDec 10, 2018
  74. Thomas GummererDec 20, 2018
  75. Duy NguyenDec 10, 2018
  76. Elijah NewrenDec 10, 2018
  77. Duy NguyenDec 10, 2018
  78. Thomas GummererDec 11, 2018
  79. Junio C HamanoDec 12, 2018
  80. 0/8 introduce no-overlay mode in git checkoutThomas Gummerer, Dec 20, 2018
  81. 1/8 move worktree tests to t24*Thomas Gummerer, Dec 20, 2018
  82. 2/8 entry: factor out unlink_entry functionThomas Gummerer, Dec 20, 2018
  83. 3/8 entry: support CE_WT_REMOVE flag in checkout_entryThomas Gummerer, Dec 20, 2018
  84. 4/8 read-cache: add invalidate parameter to remove_marked_cache_entriesThomas Gummerer, Dec 20, 2018
  85. 5/8 checkout: clarify commentThomas Gummerer, Dec 20, 2018
  86. 6/8 checkout: factor out mark_cache_entry_for_checkout functionThomas Gummerer, Dec 20, 2018
  87. 7/8 checkout: introduce --{,no-}overlay optionThomas Gummerer, Dec 20, 2018
  88. Duy NguyenDec 23, 2018
  89. Eric SunshineDec 23, 2018
  90. Thomas GummererJan 6, 2019
  91. 8/8 checkout: introduce checkout.overlayMode configThomas Gummerer, Dec 20, 2018
  92. Junio C HamanoJan 2, 2019
  93. Thomas GummererJan 6, 2019
  94. Junio C HamanoJan 7, 2019
  95. 0/8 introduce no-overlay mode in git checkoutThomas Gummerer, Jan 8, 2019
  96. 2/8 entry: factor out unlink_entry functionThomas Gummerer, Jan 8, 2019
  97. 1/8 move worktree tests to t24*Thomas Gummerer, Jan 8, 2019
  98. 4/8 read-cache: add invalidate parameter to remove_marked_cache_entriesThomas Gummerer, Jan 8, 2019
  99. 3/8 entry: support CE_WT_REMOVE flag in checkout_entryThomas Gummerer, Jan 8, 2019
  100. 5/8 checkout: clarify commentThomas Gummerer, Jan 8, 2019
  101. 6/8 checkout: factor out mark_cache_entry_for_checkout functionThomas Gummerer, Jan 8, 2019
  102. 7/8 checkout: introduce --{,no-}overlay optionThomas Gummerer, Jan 8, 2019
  103. Jonathan NiederJan 22, 2019
  104. Junio C HamanoJan 23, 2019
  105. Thomas GummererJan 23, 2019
  106. Jonathan NiederJan 23, 2019
  107. Thomas GummererJan 24, 2019
  108. Junio C HamanoJan 23, 2019
  109. Jonathan NiederJan 24, 2019
  110. Thomas GummererJan 24, 2019
  111. Junio C HamanoJan 24, 2019
  112. Jonathan NiederJan 25, 2019
  113. Duy NguyenJan 25, 2019
  114. Philip OakleyFeb 9, 2019
  115. 8/8 checkout: introduce checkout.overlayMode configThomas Gummerer, Jan 8, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.