| 4461 | } |
| 4462 | |
| 4463 | fn verify_worktree_path_set<'a>( |
| 4464 | &self, |
| 4465 | prospective: &ProjectTree, |
| 4466 | changed: impl IntoIterator<Item = &'a str>, |
| 4467 | branch_name: &str, |
| 4468 | git: &GitRepository, |
| 4469 | ) -> CliResult<()> { |
| 4470 | if git |
| 4471 | .head() |
| 4472 | .ok() |
| 4473 | .and_then(|head| head.shorthand().ok().map(str::to_owned)) |
| 4474 | .as_deref() |
| 4475 | != Some(branch_name) |
| 4476 | { |
| 4477 | return Ok(()); |
| 4478 | } |
| 4479 | let root = git |
| 4480 | .workdir() |
| 4481 | .ok_or_else(|| git_error("checked-out import branch has no worktree"))?; |
| 4482 | let filter = GitAttributesFilter::for_repository(root); |
| 4483 | let mut present = atomic_repository::worktree_presence::WorktreeEntries::new(root); |
| 4484 | let expected: BTreeMap<_, _> = prospective |
| 4485 | .manifest |
| 4486 | .entries |
| 4487 | .iter() |
| 4488 | .map(|entry| (entry.path.as_bytes(), entry)) |
| 4489 | .collect(); |
| 4490 | for path in changed { |
| 4491 | let repo_path = RepoPath::from_bytes(path.as_bytes()) |
| 4492 | .map_err(|error| git_error(format!("invalid changed path '{path}': {error}")))?; |
| 4493 | // CB-9C path fidelity: the disk holds the raw Git bytes; the |
| 4494 | // canonical String identity decodes before filesystem access. |
| 4495 | let physical = root.join(canonical_tree_path(path)); |
| 4496 | let Some(entry) = expected.get(repo_path.as_bytes()) else { |
| 4497 | let prefix = format!("{path}/"); |
| 4498 | let needs_directory = expected |
| 4499 | .keys() |
| 4500 | .any(|candidate| candidate.starts_with(prefix.as_bytes())); |
| 4501 | // Exact-name lookup: `symlink_metadata` resolves the old |
| 4502 | // spelling of a case-only rename on a case-insensitive |
| 4503 | // filesystem, and children behind an ancestor that became a |
| 4504 | // symlink to a directory; neither is a lingering Git path. |
| 4505 | let lingering = present |
| 4506 | .exact_metadata(&canonical_tree_path(path)) |
| 4507 | .map_err(|error| { |
| 4508 | git_error(format!( |
| 4509 | "cannot inspect deleted worktree path '{path}': {error}" |
| 4510 | )) |
| 4511 | })? |
| 4512 | .is_some_and(|metadata| !(needs_directory && metadata.file_type().is_dir())); |
| 4513 | if lingering { |
| 4514 | return Err(git_error(format!( |
| 4515 | "deleted Git path '{path}' is still present in the worktree" |
| 4516 | ))); |
| 4517 | } |
| 4518 | continue; |
| 4519 | }; |
| 4520 | if entry.disposition != ManifestDisposition::Included |