|
9 | 9 | #include "copy.h" |
10 | 10 | #include "dir.h" |
11 | 11 | #include "environment.h" |
| 12 | +#include "fsmonitor-settings.h" |
12 | 13 | #include "gettext.h" |
13 | 14 | #include "hex.h" |
14 | 15 | #include "object-file.h" |
|
21 | 22 | #include "refs.h" |
22 | 23 | #include "remote.h" |
23 | 24 | #include "run-command.h" |
| 25 | +#include "repo-settings.h" |
24 | 26 | #include "hook.h" |
25 | 27 | #include "sigchain.h" |
26 | 28 | #include "submodule.h" |
27 | 29 | #include "utf8.h" |
28 | 30 | #include "worktree.h" |
29 | 31 | #include "quote.h" |
| 32 | +#include "trace2.h" |
30 | 33 |
|
31 | 34 | #define BUILTIN_WORKTREE_ADD_USAGE \ |
32 | 35 | N_("git worktree add [-f] [--detach] [--checkout] [--lock [--reason <string>]]\n" \ |
@@ -409,6 +412,32 @@ static int checkout_worktree(const struct add_opts *opts, |
409 | 412 | return run_command(&cp); |
410 | 413 | } |
411 | 414 |
|
| 415 | +static void prime_worktree_clean_status_proof(const char *path) |
| 416 | +{ |
| 417 | + struct child_process cp = CHILD_PROCESS_INIT; |
| 418 | + int ret; |
| 419 | + |
| 420 | + /* |
| 421 | + * The checkout creates the linked index before it has a provider epoch |
| 422 | + * from which to certify the worktree. Establish that epoch while this |
| 423 | + * writer can still update the index; a later read-only status cannot |
| 424 | + * persist the missing proof. |
| 425 | + */ |
| 426 | + cp.git_cmd = 1; |
| 427 | + cp.dir = path; |
| 428 | + cp.no_stdin = 1; |
| 429 | + cp.no_stdout = 1; |
| 430 | + cp.no_stderr = 1; |
| 431 | + strvec_pushl(&cp.args, "status", "--porcelain=v2", |
| 432 | + "--untracked-files=normal", NULL); |
| 433 | + strvec_push(&cp.env, GIT_DIR_ENVIRONMENT); |
| 434 | + strvec_push(&cp.env, GIT_WORK_TREE_ENVIRONMENT); |
| 435 | + strvec_push(&cp.env, "GIT_OPTIONAL_LOCKS=1"); |
| 436 | + ret = run_command(&cp); |
| 437 | + trace2_data_intmax("worktree", the_repository, |
| 438 | + "add/clean-status-primed", !ret); |
| 439 | +} |
| 440 | + |
412 | 441 | static int make_worktree_orphan(const char * ref, const struct add_opts *opts, |
413 | 442 | struct strvec *child_env) |
414 | 443 | { |
@@ -593,6 +622,15 @@ static int add_worktree(const char *path, const char *refname, |
593 | 622 | if (opts->checkout && |
594 | 623 | (ret = checkout_worktree(opts, &child_env))) |
595 | 624 | goto done; |
| 625 | + if (opts->checkout && |
| 626 | + fsm_settings__get_mode(the_repository) == FSMONITOR_MODE_IPC && |
| 627 | + the_repository->settings.core_untracked_cache == |
| 628 | + UNTRACKED_CACHE_WRITE && |
| 629 | + !getenv(INDEX_ENVIRONMENT) && |
| 630 | + !getenv(GIT_COMMON_DIR_ENVIRONMENT) && |
| 631 | + !getenv(DB_ENVIRONMENT) && |
| 632 | + !getenv(ALTERNATE_DB_ENVIRONMENT)) |
| 633 | + prime_worktree_clean_status_proof(path); |
596 | 634 |
|
597 | 635 | is_junk = 0; |
598 | 636 | FREE_AND_NULL(junk_work_tree); |
|
0 commit comments