Skip to content

Commit 7448601

Browse files
Kevin Willforddscho
authored andcommitted
sparse-checkout: avoid writing entries with the skip-worktree bit
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 <[email protected]>
1 parent 78e7b66 commit 7448601

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

apply.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "dir.h"
2121
#include "environment.h"
2222
#include "gettext.h"
23+
#include "gvfs.h"
2324
#include "hex.h"
2425
#include "xdiff-interface.h"
2526
#include "merge-ll.h"
@@ -3373,6 +3374,25 @@ static int checkout_target(struct index_state *istate,
33733374
{
33743375
struct checkout costate = CHECKOUT_INIT;
33753376

3377+
/*
3378+
* Do not checkout the entry if the skipworktree bit is set
3379+
*
3380+
* Both callers of this method (check_preimage and load_current)
3381+
* check for the existance of the file before calling this
3382+
* method so we know that the file doesn't exist at this point
3383+
* and we don't need to perform that check again here.
3384+
* We just need to check the skip-worktree and return.
3385+
*
3386+
* This is to prevent git from creating a file in the
3387+
* working directory that has the skip-worktree bit on,
3388+
* then updating the index from the patch and not keeping
3389+
* the working directory version up to date with what it
3390+
* changed the index version to be.
3391+
*/
3392+
if (gvfs_config_is_set(istate->repo, GVFS_USE_VIRTUAL_FILESYSTEM) &&
3393+
ce_skip_worktree(ce))
3394+
return 0;
3395+
33763396
costate.refresh_cache = 1;
33773397
costate.istate = istate;
33783398
if (checkout_entry(ce, &costate, NULL, NULL) ||

0 commit comments

Comments
 (0)