Skip to content

fix: backup existing hook before overwriting during install#8

Merged
doanbactam merged 1 commit intomasterfrom
fix/hook-backup-before-overwrite
Apr 3, 2026
Merged

fix: backup existing hook before overwriting during install#8
doanbactam merged 1 commit intomasterfrom
fix/hook-backup-before-overwrite

Conversation

@doanbactam
Copy link
Copy Markdown
Owner

@doanbactam doanbactam commented Apr 3, 2026

Summary

  • Detect if an existing commit-msg hook at ~/.git-templates/hooks/commit-msg is not from nococli before overwriting
  • Backup non-nococli hooks to commit-msg.bak before writing our hook
  • Restore the backup when running nococli uninstall
  • Wire up the previously unused --force CLI flag (skip backup, overwrite directly)

Changed files

  • src/utils/hook.ts — added NOCO_HOOK_MARKERS constant and isNococliHook() detector
  • src/install.ts — backup logic before writeFile, respects force option
  • src/uninstall.ts — restore .bak after removing nococli hook
  • src/cli.ts — pass force flag to install()

Test plan

  • bunx tsc --noEmit passes
  • bun test — 27/27 existing tests pass
  • Manual: create a fake hook, run nococli install, verify .bak created
  • Manual: run nococli uninstall, verify hook restored from .bak
  • Manual: run nococli install again, verify no .bak (already nococli hook)
  • Manual: run nococli install --force with fake hook, verify no .bak

@doanbactam doanbactam force-pushed the fix/hook-backup-before-overwrite branch from 17ebe5a to f902a67 Compare April 3, 2026 09:49
Previously, `nococli install` would unconditionally overwrite any existing
hook at ~/.git-templates/hooks/commit-msg without backup. Now it detects
non-nococli hooks, backs them up to .bak, and restores on uninstall.
Also wires up the previously unused --force flag.
@doanbactam doanbactam force-pushed the fix/hook-backup-before-overwrite branch from f902a67 to bedda60 Compare April 3, 2026 09:53
@doanbactam doanbactam merged commit f9363a5 into master Apr 3, 2026
2 checks passed
@doanbactam doanbactam deleted the fix/hook-backup-before-overwrite branch April 3, 2026 09:55
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.

2 participants