Skip to content

fix(hook): align backup filename between install and uninstall to prevent data loss - #480

Merged
ajianaz merged 1 commit into
developfrom
fix/hook-backup-filename-mismatch
Aug 4, 2026
Merged

fix(hook): align backup filename between install and uninstall to prevent data loss#480
ajianaz merged 1 commit into
developfrom
fix/hook-backup-filename-mismatch

Conversation

@ajianaz

@ajianaz ajianaz commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

What

Fixes a data loss bug in the pre-commit hook install/uninstall lifecycle.

Bug: Backup filename mismatch between install and uninstall

Operation Backup filename (before) Backup filename (after)
install_hook() pre-commit.bak pre-commit.pre-cora.bak
uninstall_hook() searches pre-commit.cora.bak + pre-commit.pre-cora.bak searches pre-commit.pre-cora.bak only

Scenario:

  1. User has an existing pre-commit hook (e.g., husky, lefthook, custom script)
  2. User runs cora hook install → original hook backed up to pre-commit.bak
  3. User later runs cora hook uninstall → cora searches for pre-commit.cora.bak (not found) and pre-commit.pre-cora.bak (not found)
  4. Cora deletes the hook entirely → user's original hook is lost forever

Fix

  • install_hook(): changed backup filename from pre-commit.bakpre-commit.pre-cora.bak (matches what uninstall expects)
  • uninstall_hook(): removed dead pre-commit.cora.bak path (never written by anyone)

Why

This is silent data loss. Users who trusted cora hook install over their existing hooks would permanently lose their configuration on uninstall. No error, no warning — just gone.

Testing

  • cargo test --bin cora — 777 passed, 0 failed (was 776, +1 new regression test)
  • cargo clippy --bin cora --tests -- -D warnings — clean
  • cargo fmt --all — clean
  • Cora pre-commit review — No issues found

New test backup_filename_is_pre_cora_bak verifies:

  1. Source does NOT reference "pre-commit.bak" (generic, was root cause)
  2. Source does NOT reference "pre-commit.cora.bak" (dead code)
  3. Source consistently uses "pre-commit.pre-cora.bak" for both install and uninstall

…vent data loss

install_hook() backed up existing non-cora hooks to 'pre-commit.bak',
but uninstall_hook() looked for 'pre-commit.cora.bak' and
'pre-commit.pre-cora.bak'. Neither matched — so uninstall would delete
the cora hook WITHOUT restoring the user's original, losing it forever.

Fix: install now writes 'pre-commit.pre-cora.bak' (matching what
uninstall searches for), and the dead 'pre-commit.cora.bak' path in
uninstall is removed.

Added regression test that verifies backup filename consistency.
@ajianaz
ajianaz force-pushed the fix/hook-backup-filename-mismatch branch from 1742e19 to c3a6975 Compare August 4, 2026 10:47
@ajianaz
ajianaz merged commit 9d2b0d1 into develop Aug 4, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant