зеркало из https://github.com/microsoft/git.git
gvfs: prevent files to be deleted outside the sparse checkout
Prevent the sparse checkout to delete files that were marked with skip-worktree bit and are not in the sparse-checkout file. This is because everything with the skip-worktree bit turned on is being virtualized and will be removed with the change of HEAD. There was only one failing test when running with these changes that was checking to make sure the worktree narrows on checkout which was expected since we would no longer be narrowing the worktree. Update 2022-04-05: temporarily set 'sparse.expectfilesoutsideofpatterns' in test (until we start disabling the "remove present-despite-SKIP_WORKTREE" behavior with 'core.virtualfilesystem' in a later commit). Signed-off-by: Kevin Willford <kewillf@microsoft.com>
This commit is contained in:
Родитель
6247e1221d
Коммит
66a01f8d9e
|
@ -726,6 +726,15 @@ core.gvfs::
|
||||||
Bit value 4
|
Bit value 4
|
||||||
Normally git write-tree ensures that the objects referenced by the
|
Normally git write-tree ensures that the objects referenced by the
|
||||||
directory exist in the object database. This option disables this check.
|
directory exist in the object database. This option disables this check.
|
||||||
|
GVFS_NO_DELETE_OUTSIDE_SPARSECHECKOUT::
|
||||||
|
Bit value 8
|
||||||
|
When marking entries to remove from the index and the working
|
||||||
|
directory this option will take into account what the
|
||||||
|
skip-worktree bit was set to so that if the entry has the
|
||||||
|
skip-worktree bit set it will not be removed from the working
|
||||||
|
directory. This will allow virtualized working directories to
|
||||||
|
detect the change to HEAD and use the new commit tree to show
|
||||||
|
the files that are in the working directory.
|
||||||
--
|
--
|
||||||
|
|
||||||
core.sparseCheckout::
|
core.sparseCheckout::
|
||||||
|
|
1
gvfs.h
1
gvfs.h
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
#define GVFS_SKIP_SHA_ON_INDEX (1 << 0)
|
#define GVFS_SKIP_SHA_ON_INDEX (1 << 0)
|
||||||
#define GVFS_MISSING_OK (1 << 2)
|
#define GVFS_MISSING_OK (1 << 2)
|
||||||
|
#define GVFS_NO_DELETE_OUTSIDE_SPARSECHECKOUT (1 << 3)
|
||||||
|
|
||||||
static inline int gvfs_config_is_set(int mask) {
|
static inline int gvfs_config_is_set(int mask) {
|
||||||
return (core_gvfs & mask) == mask;
|
return (core_gvfs & mask) == mask;
|
||||||
|
|
|
@ -103,6 +103,26 @@ test_expect_success 'in partial clone, sparse checkout only fetches needed blobs
|
||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'checkout does not delete items outside the sparse checkout file' '
|
||||||
|
# The "sparse.expectfilesoutsideofpatterns" config will prevent the
|
||||||
|
# SKIP_WORKTREE flag from being dropped on files present on-disk.
|
||||||
|
test_config sparse.expectfilesoutsideofpatterns true &&
|
||||||
|
|
||||||
|
test_config core.gvfs 8 &&
|
||||||
|
git checkout -b outside &&
|
||||||
|
echo "new file1" >d &&
|
||||||
|
git add --sparse d &&
|
||||||
|
git commit -m "branch initial" &&
|
||||||
|
echo "new file1" >e &&
|
||||||
|
git add --sparse e &&
|
||||||
|
git commit -m "skipped worktree" &&
|
||||||
|
git update-index --skip-worktree e &&
|
||||||
|
echo "/d" >.git/info/sparse-checkout &&
|
||||||
|
git checkout HEAD^ &&
|
||||||
|
test_path_is_file d &&
|
||||||
|
test_path_is_file e
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success MINGW 'no unnecessary opendir() with fscache' '
|
test_expect_success MINGW 'no unnecessary opendir() with fscache' '
|
||||||
git clone . fscache-test &&
|
git clone . fscache-test &&
|
||||||
(
|
(
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
|
#include "gvfs.h"
|
||||||
#include "strvec.h"
|
#include "strvec.h"
|
||||||
#include "repository.h"
|
#include "repository.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -2558,6 +2559,27 @@ static int deleted_entry(const struct cache_entry *ce,
|
||||||
|
|
||||||
if (!(old->ce_flags & CE_CONFLICTED) && verify_uptodate(old, o))
|
if (!(old->ce_flags & CE_CONFLICTED) && verify_uptodate(old, o))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* When marking entries to remove from the index and the working
|
||||||
|
* directory this option will take into account what the
|
||||||
|
* skip-worktree bit was set to so that if the entry has the
|
||||||
|
* skip-worktree bit set it will not be removed from the working
|
||||||
|
* directory. This will allow virtualized working directories to
|
||||||
|
* detect the change to HEAD and use the new commit tree to show
|
||||||
|
* the files that are in the working directory.
|
||||||
|
*
|
||||||
|
* old is the cache_entry that will have the skip-worktree bit set
|
||||||
|
* which will need to be preserved when the CE_REMOVE entry is added
|
||||||
|
*/
|
||||||
|
if (gvfs_config_is_set(GVFS_NO_DELETE_OUTSIDE_SPARSECHECKOUT) &&
|
||||||
|
old &&
|
||||||
|
old->ce_flags & CE_SKIP_WORKTREE) {
|
||||||
|
add_entry(o, old, CE_REMOVE, 0);
|
||||||
|
invalidate_ce_path(old, o);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
add_entry(o, ce, CE_REMOVE, 0);
|
add_entry(o, ce, CE_REMOVE, 0);
|
||||||
invalidate_ce_path(ce, o);
|
invalidate_ce_path(ce, o);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Загрузка…
Ссылка в новой задаче