git/builtin
Kevin Willford 7f8eb1a7c6 reset: fix mixed reset when using virtual filesystem
During the 2.35.0 rebase, we ejected 570f64b (Fix reset when using the
sparse-checkout feature., 2017-03-15) because of a similar change
upstream that actually works with the expected behavior of
sparse-checkout.

That commit only ever existed in microsoft/git, but when it was
considered for upstream we realized that it behaved strangely for a
sparse-checkout scenario.

The root problem is that during a mixed reset, 'git reset <commit>'
updates the index to aggree with <commit> but leaves the worktree the
same as it was before. The issue with sparse-checkout is that some files
might not be in the worktree and thus the information from those files
would be "lost".

The upstream decision was to leave these files as ignored, because
that's what the SKIP_WORKTREE bit means: don't put these files in the
worktree and ignore their contents. If there already were files in the
worktree, then Git does not change them. The case for "losing" data is
if a committed change outside of the sparse-checkout was in the previous
HEAD position. However, this information could be recovered from the
reflog.

The case where this is different is in a virtualized filesystem. The
virtualization is projecting the index contents onto the filesystem, so
we need to do something different here. In a virtual environment, every
file is considered "important" and we abuse the SKIP_WORKTREE bit to
indicate that Git does not need to process a projected file. When a file
is populated, the virtual filesystem hook provides the information for
removing the SKIP_WORKTREE bit.

In the case of these mixed resets, we have the issue where we change the
projection of the worktree for these cache entries that change. If a
file is populated in the worktree, then the populated file will persist
and appear in a follow-up 'git status'. However, if the file is not
populated and only projected, we change the projection from the current
value to the new value, leaving a clean 'git status'.

The previous version of this commit includes a call to checkout_entry(),
which populates the file. This causes the file to be actually in the
working tree and no longer projected.

To make this work with the upstream changes, stop setting the
skip-worktree bit for the new cache entry. This seemed to work fine
without this change, but it's likely due to some indirection with the
virtual filesystem. Better to do the best-possible thing here so we
don't hide a corner-case bug by accident.

Helped-by: Victoria Dye <vdye@github.com>
Signed-off-by: Kevin Willford <kewillf@microsoft.com>
Signed-off-by: Derrick Stolee <derrickstolee@github.com>
2023-03-14 11:09:47 +01:00
..
add.c add/rm: allow adding sparse entries when virtual 2023-03-14 11:09:43 +01:00
am.c Merge branch 'ab/hook-api-with-stdin' 2023-02-22 14:55:45 -08:00
annotate.c
apply.c apply.c: remove unnecessary include 2022-04-06 09:42:14 -07:00
archive.c parse-options: PARSE_OPT_KEEP_UNKNOWN only applies to --options 2022-08-19 11:13:14 -07:00
bisect.c bisect: remove Cogito-related code 2023-01-13 14:17:14 -08:00
blame.c doc txt & -h consistency: make "annotate" consistent 2022-10-13 09:32:57 -07:00
branch.c Merge branch 'rj/branch-copy-and-rename' 2022-12-19 11:46:18 +09:00
bugreport.c built-ins: use free() not UNLEAK() if trivial, rm dead code 2022-11-21 12:32:48 +09:00
bundle.c Merge branch 'ab/bundle-wo-args' 2023-01-05 15:07:22 +09:00
cat-file.c Merge branch 'sa/cat-file-mailmap--batch-check' 2023-01-05 15:07:17 +09:00
check-attr.c attr: add flag `--source` to work with tree-ish 2023-01-14 08:49:55 -08:00
check-ignore.c cocci: apply "pending" index-compatibility to some "builtin/*.c" 2022-11-21 12:06:15 +09:00
check-mailmap.c
check-ref-format.c check-ref-format: fix trivial memory leak 2022-07-01 11:43:42 -07:00
checkout--worker.c pkt-line.[ch]: remove unused packet_read_line_buf() 2021-10-15 13:09:40 -07:00
checkout-index.c cocci: apply "pending" index-compatibility to some "builtin/*.c" 2022-11-21 12:06:15 +09:00
checkout.c Trace2:gvfs:experiment: capture more 'tracking' details 2023-03-14 11:09:32 +01:00
clean.c clean: suggest using `core.longPaths` if paths are too long to remove 2023-03-13 18:23:43 +01:00
clone.c Merge branch 'ab/various-leak-fixes' 2023-02-22 14:55:45 -08:00
column.c column: fix parsing of the '--nl' option 2021-08-26 14:36:27 -07:00
commit-graph.c commit-graph: fix a parse_options_concat() leak 2023-02-06 15:34:38 -08:00
commit-tree.c doc txt & -h consistency: add missing options 2022-10-13 09:32:57 -07:00
commit.c gvfs:trace2:data: status deserialization information 2023-03-14 11:09:31 +01:00
config.c built-ins: use free() not UNLEAK() if trivial, rm dead code 2022-11-21 12:32:48 +09:00
count-objects.c i18n: remove from i18n strings that do not hold translatable parts 2022-02-04 13:58:28 -08:00
credential-cache--daemon.c credential: new attribute password_expiry_utc 2023-02-22 15:18:58 -08:00
credential-cache.c credential-cache: check for windows specific errors 2021-09-14 09:30:54 -07:00
credential-store.c Use a better name for the function interpolating paths 2021-07-26 12:17:16 -07:00
credential.c doc: fix git credential synopsis 2021-10-28 09:57:09 -07:00
describe.c cocci: apply "pending" index-compatibility to some "builtin/*.c" 2022-11-21 12:06:15 +09:00
diagnose.c Merge branch 'ab/doc-synopsis-and-cmd-usage' 2022-10-28 11:26:54 -07:00
diff-files.c cocci: apply "pending" index-compatibility to some "builtin/*.c" 2022-11-21 12:06:15 +09:00
diff-index.c cocci: apply "pending" index-compatibility to some "builtin/*.c" 2022-11-21 12:06:15 +09:00
diff-tree.c cocci: apply "pending" index-compatibility to some "builtin/*.c" 2022-11-21 12:06:15 +09:00
diff.c Merge branch 'ab/various-leak-fixes' 2022-12-14 15:55:46 +09:00
difftool.c Introduce helper to create symlinks that knows about index_state 2023-03-13 18:23:45 +01:00
fast-export.c diff: mark unused parameters in callbacks 2022-12-13 22:16:23 +09:00
fast-import.c git-compat-util.h: use "UNUSED", not "UNUSED(var)" 2022-09-01 10:49:48 -07:00
fetch-pack.c list-objects-filter: add and use initializers 2022-09-12 08:38:59 -07:00
fetch.c fetch: reprepare packs before checking connectivity 2023-03-14 11:09:35 +01:00
fmt-merge-msg.c merge: allow to pretend a merge is made into a different branch 2021-12-20 14:55:02 -08:00
for-each-ref.c for-each-ref: delay parsing of --sort=<atom> options 2021-10-20 14:33:07 -07:00
for-each-repo.c for-each-repo: interpolate repo path arguments 2022-11-14 22:39:25 -05:00
fsck.c cocci: apply "pending" index-compatibility to some "builtin/*.c" 2022-11-21 12:06:15 +09:00
fsmonitor--daemon.c Merge branch 'sx/pthread-error-check-fix' 2022-12-19 11:46:17 +09:00
gc.c maintenance: delete stale lock files 2023-03-14 11:09:47 +01:00
get-tar-commit-id.c
grep.c builtin/{grep,log}.: don't define "USE_THE_INDEX_COMPATIBILITY_MACROS" 2022-11-21 12:06:14 +09:00
hash-object.c Merge branch 'jk/hash-object-literally-fd-leak' 2023-01-27 08:51:41 -08:00
help.c Merge branch 'ab/doc-synopsis-and-cmd-usage' 2022-10-28 11:26:54 -07:00
hook.c hook: support a --to-stdin=<path> option 2023-02-08 12:50:03 -08:00
index-pack.c index-pack: avoid immediate object fetch while parsing packfile 2023-03-14 11:09:33 +01:00
init-db.c Introduce helper to create symlinks that knows about index_state 2023-03-13 18:23:45 +01:00
interpret-trailers.c doc txt & -h consistency: add missing options 2022-10-13 09:32:57 -07:00
log.c format.attach: allow empty value to disable multi-part messages 2023-02-17 15:43:09 -08:00
ls-files.c ls-files: fix a --with-tree memory leak 2022-11-21 12:32:48 +09:00
ls-remote.c doc/ls-remote: clarify pattern format 2023-02-10 21:57:51 -08:00
ls-tree.c Merge branch 'rs/ls-tree-path-expansion-fix' 2023-01-23 13:39:50 -08:00
mailinfo.c mailinfo: allow squelching quoted CRLF warning 2021-05-10 15:06:22 +09:00
mailsplit.c Merge branch 'ep/maint-equals-null-cocci' 2022-05-20 15:26:59 -07:00
merge-base.c doc txt & -h consistency: make output order consistent 2022-10-13 09:32:56 -07:00
merge-file.c merge-file: fix memory leaks on error path 2022-07-01 11:43:43 -07:00
merge-index.c cocci: apply "pending" index-compatibility to some "builtin/*.c" 2022-11-21 12:06:15 +09:00
merge-ours.c cocci: apply "pending" index-compatibility to some "builtin/*.c" 2022-11-21 12:06:15 +09:00
merge-recursive.c gettext API users: don't explicitly cast ngettext()'s "n" 2022-03-07 11:57:52 -08:00
merge-tree.c Merge branch 'jk/unused-post-2.39' 2022-12-26 11:42:05 +09:00
merge.c Merge branch 'ab/various-leak-fixes' 2023-02-22 14:55:45 -08:00
mktag.c Merge branch 'ab/object-file-api-updates' 2022-03-16 17:53:08 -07:00
mktree.c mktree: do not check type of remote objects 2022-06-21 10:12:15 -07:00
multi-pack-index.c multi-pack-index: avoid writing to global in option callback 2022-10-06 09:56:51 -07:00
mv.c cocci & cache.h: apply pending "index_cache_pos" rule 2023-02-10 11:37:27 -08:00
name-rev.c Merge branch 'ab/various-leak-fixes' 2023-02-22 14:55:45 -08:00
notes.c notes: avoid empty line in template 2022-11-16 14:57:32 -05:00
pack-objects.c Merge branch 'rs/size-t-fixes' 2023-02-15 17:11:53 -08:00
pack-redundant.c doc txt & -h consistency: fix mismatching labels 2022-10-13 09:32:56 -07:00
pack-refs.c doc txt & -h consistency: add missing options and labels 2022-10-13 09:32:56 -07:00
patch-id.c builtin: patch-id: remove unused diff-tree prefix 2022-10-24 15:44:20 -07:00
prune-packed.c i18n: remove from i18n strings that do not hold translatable parts 2022-02-04 13:58:28 -08:00
prune.c prune: quiet ENOENT on missing directories 2022-11-21 15:58:54 +09:00
pull.c {builtin/*,repository}.c: add & use "USE_THE_INDEX_VARIABLE" 2022-11-21 12:06:15 +09:00
push.c push: free_refs() the "local_refs" in set_refspecs() 2023-02-06 15:34:40 -08:00
range-diff.c diff: factor out add_diff_options() 2022-12-02 08:25:29 +09:00
read-tree.c read-tree: add "--super-prefix" option, eliminate global 2022-12-26 10:21:44 +09:00
rebase.c builtin/rebase.c: free() "options.strategy_opts" 2023-02-06 16:03:53 -08:00
receive-pack.c receive-pack: release the linked "struct command *" list 2023-02-06 15:34:40 -08:00
reflog.c refs: unify parse_worktree_ref() and ref_type() 2022-09-19 11:11:11 -07:00
remote-ext.c convert trivial uses of strncmp() to skip_prefix() 2023-01-08 10:34:37 +09:00
remote-fd.c convert trivial uses of strncmp() to starts_with() 2023-01-08 10:34:35 +09:00
remote.c Merge branch 'rs/no-more-run-command-v' 2022-11-08 17:15:12 -05:00
repack.c repack: fix leaks on error with "goto cleanup" 2023-02-06 15:34:37 -08:00
replace.c refs: use ref_namespaces for replace refs base 2022-08-05 14:13:12 -07:00
rerere.c diff: mark unused parameters in callbacks 2022-12-13 22:16:23 +09:00
reset.c reset: fix mixed reset when using virtual filesystem 2023-03-14 11:09:47 +01:00
rev-list.c Merge branch 'ps/receive-use-only-advertised' 2022-11-23 11:22:25 +09:00
rev-parse.c Merge branch 'ab/various-leak-fixes' 2022-12-14 15:55:46 +09:00
revert.c builtin/revert.c: move free-ing of "revs" to replay_opts_release() 2023-02-06 16:03:52 -08:00
rm.c add/rm: allow adding sparse entries when virtual 2023-03-14 11:09:43 +01:00
send-pack.c doc txt & -h consistency: add missing options and labels 2022-10-13 09:32:56 -07:00
shortlog.c shortlog: implement `--group=committer` in terms of `--group=<format>` 2022-10-24 14:48:05 -07:00
show-branch.c show-branch: free() allocated "head" before return 2023-02-06 15:34:39 -08:00
show-index.c builtin/show-index: set the algorithm for object IDs 2021-04-27 16:31:39 +09:00
show-ref.c Merge branch 'ab/doc-synopsis-and-cmd-usage' 2022-10-28 11:26:54 -07:00
sparse-checkout.c sparse-checkout: add config to disable deleting dirs 2023-03-14 10:33:05 +01:00
stash.c Merge branch 'ab/various-leak-fixes' 2023-02-22 14:55:45 -08:00
stripspace.c i18n: remove from i18n strings that do not hold translatable parts 2022-02-04 13:58:28 -08:00
submodule--helper.c *: fix typos which duplicate a word 2023-01-08 10:28:34 +09:00
symbolic-ref.c Merge branch 'ab/doc-synopsis-and-cmd-usage' 2022-10-28 11:26:54 -07:00
tag.c doc txt & -h consistency: add missing options and labels 2022-10-13 09:32:56 -07:00
unpack-file.c unpack-file: fix ancient leak in create_temp_file() 2022-11-21 12:32:48 +09:00
unpack-objects.c unpack-objects: use stream_loose_object() to unpack large objects 2022-06-13 10:22:36 -07:00
update-index.c gvfs: block unsupported commands when running in a GVFS repo 2023-03-14 11:09:28 +01:00
update-microsoft-git.c update-microsoft-git: use brew on macOS 2023-03-14 11:09:37 +01:00
update-ref.c update-ref: fix streaming of status updates 2021-09-03 11:35:15 -07:00
update-server-info.c doc txt & -h consistency: add missing options and labels 2022-10-13 09:32:56 -07:00
upload-archive.c doc txt & -h consistency: fix mismatching labels 2022-10-13 09:32:56 -07:00
upload-pack.c doc txt & -h consistency: add missing options and labels 2022-10-13 09:32:56 -07:00
var.c var: add GIT_SEQUENCE_EDITOR variable 2022-12-18 11:48:26 +09:00
verify-commit.c doc txt & -h consistency: add missing options and labels 2022-10-13 09:32:56 -07:00
verify-pack.c doc txt & -h consistency: add or fix optional "--" syntax 2022-10-13 09:32:56 -07:00
verify-tag.c doc txt & -h consistency: add missing options and labels 2022-10-13 09:32:56 -07:00
worktree.c worktree: allow in Scalar repositories 2023-03-14 11:09:29 +01:00
write-tree.c cocci & cache-tree.h: migrate "write_cache_as_tree" to "*_index_*" 2023-02-10 11:37:49 -08:00