MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / migrate_legacy_import_hooks

Function migrate_legacy_import_hooks

atomic-cli/src/commands/git/hooks.rs:445–492  ·  view source on GitHub ↗
(hooks_dir: &Path, binary: &Path)

Source from the content-addressed store, hash-verified

443}
444
445fn 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
494fn write_new_executable(path: &Path, content: &[u8]) -> io::Result<()> {
495 let mut file = OpenOptions::new().write(true).create_new(true).open(path)?;

Callers 1

enable_shimFunction · 0.85

Calls 9

is_legacy_atomic_onlyFunction · 0.85
print_infoFunction · 0.85
git_errorFunction · 0.70
readFunction · 0.50
kindMethod · 0.45
is_fileMethod · 0.45
lenMethod · 0.45
as_bytesMethod · 0.45

Tested by

no test coverage detected