(root: &Path)
| 261 | } |
| 262 | |
| 263 | pub(super) fn git_hook_context(root: &Path) -> CliResult<GitHookContext> { |
| 264 | let common_dir = match observe_git(root) |
| 265 | .map_err(|error| git_error(format!("cannot resolve Git administrative paths: {error}")))? |
| 266 | { |
| 267 | GitObservation::NoGit { .. } => { |
| 268 | return Err(git_error("cannot enable the shim outside a Git repository")); |
| 269 | } |
| 270 | GitObservation::Repository(observation) => { |
| 271 | if observation.paths.worktree_root.is_none() { |
| 272 | return Err(git_error( |
| 273 | "cannot enable a working-copy hook for a bare Git repository", |
| 274 | )); |
| 275 | } |
| 276 | observation.paths.common_dir.clone() |
| 277 | } |
| 278 | }; |
| 279 | |
| 280 | let repository = GitRepository::open(root) |
| 281 | .map_err(|error| git_error(format!("cannot open Git repository: {error}")))?; |
| 282 | let config = repository |
| 283 | .config() |
| 284 | .map_err(|error| git_error(format!("cannot read Git configuration: {error}")))?; |
| 285 | let custom_hooks_path = match config.get_path("core.hooksPath") { |
| 286 | Ok(path) => Some(path), |
| 287 | Err(error) if error.code() == ErrorCode::NotFound => None, |
| 288 | Err(error) => { |
| 289 | return Err(git_error(format!( |
| 290 | "cannot read configured core.hooksPath: {error}" |
| 291 | ))) |
| 292 | } |
| 293 | }; |
| 294 | |
| 295 | Ok(GitHookContext { |
| 296 | common_dir, |
| 297 | custom_hooks_path, |
| 298 | }) |
| 299 | } |
| 300 | |
| 301 | fn dispatcher_script(binary: &Path, subcommand: &str) -> io::Result<String> { |
| 302 | let binary = shell_quote(binary)?; |
no test coverage detected