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

[PATCH 2/3] apply.c: do not checkout file when skip-worktree bit set

From
KWKevin Willford <kcwillford@gmail.com>
Date
Apr 7, 2017, 19:23 UTC
Message-ID
<20170407192357.948-3-kewillf@microsoft.com>
In-Reply-To
<20170407192357.948-1-kewillf@microsoft.com>

When using the sparse-checkout feature git should not write to the working directory for files with the skip-worktree bit on. With the skip-worktree bit on the file may or may not be in the working directory and if it is not we don't want or need to create it by calling checkout_entry.

There are two callers of checkout_target. Both of which check that the file does not exist before calling checkout_target. load_current which make a call to lstat right before calling checkout_target and check_preimage which will only run checkout_taret it stat_ret is less than zero. It sets stat_ret to zero and only if !stat->cached will it lstat the file and set stat_ret to something other than zero.

This patch checks if skip-worktree bit is on in checkout_target and just returns so that the entry doesn't not end up in the working directory. This is so that apply will not create a file in the working directory, then update the index but not keep the working directory up to date with the changes that happened in the index.

Signed-off-by: Kevin Willford <kewillf@microsoft.com>
---
 apply.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
diff --git a/apply.c b/apply.c
index 0e2caeab9c..0da5d0b7c9 100644
--- a/apply.c
+++ b/apply.c
@@ -3327,6 +3327,24 @@ static int checkout_target(struct index_state *istate,
 {
 	struct checkout costate = CHECKOUT_INIT;
 
+	/*
+	 * Do not checkout the entry if the skipworktree bit is set
+	 *
+	 * Both callers of this method (check_preimage and load_current)
+	 * check for the existance of the file before calling this
+	 * method so we know that the file doesn't exist at this point
+	 * and we don't need to perform that check again here.
+	 * We just need to check the skip-worktree and return.
+	 *
+	 * This is to prevent git from creating a file in the
+	 * working directory that has the skip-worktree bit on,
+	 * then updating the index from the patch and not keeping
+	 * the working directory version up to date with what it
+	 * changed the index version to be.
+	 */
+	if (ce_skip_worktree(ce))
+		return 0;
+
 	costate.refresh_cache = 1;
 	costate.istate = istate;
 	if (checkout_entry(ce, &costate, NULL) || lstat(ce->name, st))
-- 
2.12.2.windows.2.1.g7df5db8d31
Previous: Duy NguyenNext: Stefan Beller
Message 4 of 16 in “fix working directory file issues while using sparse-checkout”
  1. 0/3 fix working directory file issues while using sparse-checkoutKevin Willford, Apr 7, 2017
  2. 1/3 merge-recursive.c: conflict using sparse should update fileKevin Willford, Apr 7, 2017
  3. Duy NguyenApr 10, 2017
  4. 2/3 apply.c: do not checkout file when skip-worktree bit setKevin Willford, Apr 7, 2017
  5. Stefan BellerApr 7, 2017
  6. Duy NguyenApr 10, 2017
  7. 3/3 reset.c: update files when using sparse to avoid data loss.Kevin Willford, Apr 7, 2017
  8. Stefan BellerApr 7, 2017
  9. Duy NguyenApr 10, 2017
  10. Kevin WillfordApr 11, 2017
  11. Duy NguyenApr 12, 2017
  12. Kevin WillfordApr 12, 2017
  13. Duy NguyenApr 16, 2017
  14. Duy NguyenApr 17, 2017
  15. Stefan BellerApr 7, 2017
  16. Stefan BellerApr 7, 2017

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.