(hooks_dir: &Path, binary: &Path)
| 443 | } |
| 444 | |
| 445 | fn migrate_legacy_import_hooks(hooks_dir: &Path, binary: &Path) -> CliResult<()> { |
| 446 | for hook_name in ["post-commit", "post-merge", "post-rewrite"] { |
| 447 | let path = hooks_dir.join(hook_name); |
| 448 | let metadata = match fs::symlink_metadata(&path) { |
| 449 | Ok(metadata) => metadata, |
| 450 | Err(error) if error.kind() == ErrorKind::NotFound => continue, |
| 451 | Err(error) => { |
| 452 | return Err(git_error(format!( |
| 453 | "cannot inspect legacy hook '{}': {error}", |
| 454 | path.display() |
| 455 | ))) |
| 456 | } |
| 457 | }; |
| 458 | if metadata.file_type().is_symlink() || !metadata.file_type().is_file() { |
| 459 | continue; |
| 460 | } |
| 461 | let content = fs::read(&path).map_err(|error| { |
| 462 | git_error(format!( |
| 463 | "cannot inspect legacy hook '{}': {error}", |
| 464 | path.display() |
| 465 | )) |
| 466 | })?; |
| 467 | if is_legacy_atomic_only(&content) { |
| 468 | fs::remove_file(&path).map_err(|error| { |
| 469 | git_error(format!( |
| 470 | "cannot remove Atomic-owned legacy hook '{}': {error}", |
| 471 | path.display() |
| 472 | )) |
| 473 | })?; |
| 474 | print_info(&format!( |
| 475 | "Removed Atomic-owned legacy synchronous hook {}", |
| 476 | path.display() |
| 477 | )); |
| 478 | } else if content |
| 479 | .windows(LEGACY_MARKER_BEGIN.len()) |
| 480 | .any(|window| window == LEGACY_MARKER_BEGIN.as_bytes()) |
| 481 | { |
| 482 | print_unmanaged_instructions( |
| 483 | &format!( |
| 484 | "legacy Atomic section is mixed with unmanaged hook content in '{}'; the file was left untouched and the legacy import section must be removed manually", |
| 485 | path.display() |
| 486 | ), |
| 487 | binary, |
| 488 | )?; |
| 489 | } |
| 490 | } |
| 491 | Ok(()) |
| 492 | } |
| 493 | |
| 494 | fn write_new_executable(path: &Path, content: &[u8]) -> io::Result<()> { |
| 495 | let mut file = OpenOptions::new().write(true).create_new(true).open(path)?; |
no test coverage detected