Skip to content

Commit f236513

Browse files
benpeartdscho
authored andcommitted
virtualfilesystem: don't run the virtual file system hook if the index has been redirected
Fixes #13 Some git commands spawn helpers and redirect the index to a different location. These include "difftool -d" and the sequencer (i.e. `git rebase -i`, `git cherry-pick` and `git revert`) and others. In those instances we don't want to update their temporary index with our virtualization data. Helped-by: Johannes Schindelin <[email protected]> Signed-off-by: Ben Peart <[email protected]>
1 parent d991bc6 commit f236513

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

config.c

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,11 +2201,25 @@ int repo_config_get_virtualfilesystem(struct repository *r)
22012201
if (core_virtualfilesystem && !*core_virtualfilesystem)
22022202
FREE_AND_NULL(core_virtualfilesystem);
22032203

2204-
/* virtual file system relies on the sparse checkout logic so force it on */
22052204
if (core_virtualfilesystem) {
2206-
core_apply_sparse_checkout = 1;
2207-
virtual_filesystem_result = 1;
2208-
return 1;
2205+
/*
2206+
* Some git commands spawn helpers and redirect the index to a different
2207+
* location. These include "difftool -d" and the sequencer
2208+
* (i.e. `git rebase -i`, `git cherry-pick` and `git revert`) and others.
2209+
* In those instances we don't want to update their temporary index with
2210+
* our virtualization data.
2211+
*/
2212+
char *default_index_file = xstrfmt("%s/%s", r->gitdir, "index");
2213+
int should_run_hook = !strcmp(default_index_file, r->index_file);
2214+
2215+
free(default_index_file);
2216+
if (should_run_hook) {
2217+
/* virtual file system relies on the sparse checkout logic so force it on */
2218+
core_apply_sparse_checkout = 1;
2219+
virtual_filesystem_result = 1;
2220+
return 1;
2221+
}
2222+
FREE_AND_NULL(core_virtualfilesystem);
22092223
}
22102224

22112225
virtual_filesystem_result = 0;

0 commit comments

Comments
 (0)