(root: &Path)
| 370 | } |
| 371 | |
| 372 | fn resolve_git_admin(root: &Path) -> Result<Option<GitAdminPaths>, RepositoryError> { |
| 373 | // One `git rev-parse` answers every query, one line per argument in |
| 374 | // order. This runs on every working-copy validation, several times per |
| 375 | // command, so it is one subprocess rather than four. |
| 376 | let Some(lines) = run_git_optional_lines( |
| 377 | root, |
| 378 | &[ |
| 379 | "rev-parse", |
| 380 | "--show-toplevel", |
| 381 | "--git-common-dir", |
| 382 | "--git-dir", |
| 383 | "--git-path", |
| 384 | "index", |
| 385 | ], |
| 386 | )? |
| 387 | else { |
| 388 | return Ok(None); |
| 389 | }; |
| 390 | let [worktree_output, common_output, git_dir_output, index_output]: [Vec<u8>; 4] = lines |
| 391 | .try_into() |
| 392 | .map_err(|lines: Vec<Vec<u8>>| RepositoryError::InvalidRepository { |
| 393 | reason: format!( |
| 394 | "git rev-parse printed {} administrative paths, expected 4", |
| 395 | lines.len() |
| 396 | ), |
| 397 | })?; |
| 398 | let worktree_root = resolve_git_path(root, &worktree_output, true)?; |
| 399 | let common_dir = resolve_git_path(root, &common_output, true)?; |
| 400 | let worktree_git_dir = resolve_git_path(root, &git_dir_output, true)?; |
| 401 | let index_path = resolve_git_path(root, &index_output, false)?; |
| 402 | |
| 403 | Ok(Some(GitAdminPaths { |
| 404 | worktree_root, |
| 405 | common_dir, |
| 406 | worktree_git_dir, |
| 407 | index_path, |
| 408 | })) |
| 409 | } |
| 410 | |
| 411 | /// Run a Git command that prints one path per line. `None` when Git is |
| 412 | /// missing or the command fails (for example outside a Git worktree). |
no test coverage detected