Skip to content

Add git hooks package and lnk hooks CLI - #26

Merged
polymorcodeus merged 3 commits into
mainfrom
hooks
Aug 25, 2026
Merged

Add git hooks package and lnk hooks CLI#26
polymorcodeus merged 3 commits into
mainfrom
hooks

Conversation

@polymorcodeus

Copy link
Copy Markdown
Owner

Summary

Adds git hook automation for lnk: a post-merge hook in the lnk repo and a post-checkout hook in project repos. Makes ProjectRestore idempotent and introduces collision-safe hook restore paths so hooks can run unattended on every checkout without silently replacing user files.

What's new

  • internal/hooks package - installs and uninstalls lnk-managed post-merge and post-checkout scripts, using marker comments to refuse overwriting foreign hooks.
  • lnk hooks CLI - install, uninstall, and run commands, with --project targeting a project repo instead of the lnk repo.
  • Hook runner - service.RunHook dispatches to collision-safe restore logic and wraps every body in runWithTimeout, so a hung or failing restore never blocks the git operation.
  • Idempotent project restore - ProjectRestore now skips symlinks that already resolve to the correct storage target instead of recreating them.
  • Collision-safe restore - RestoreHook and ProjectRestoreHook create missing symlinks, replace stale symlinks, and report real-file collisions without backing them up.

Usage

CommandPurpose
lnk hooks installinstall the post-merge hook in the lnk repo
lnk hooks install --projectinstall the post-checkout hook in the current project repo
lnk hooks uninstallremove lnk's post-merge hook
lnk hooks uninstall --projectremove lnk's post-checkout hook
lnk hooks run <hook-name> [args...]entry point called by the installed git hook scripts

Behavior changes / guardrails

  • Hooks are opt-in; install refuses to overwrite a hook that was not written by lnk.
  • post-checkout resolves the project root from the current working directory and refuses to treat the lnk repo (or any clone of it) as a project.
  • Hook restore reports real-file collisions to stderr and leaves the files in place; no .lnk-backup is created during hook execution.
  • A hung or erroring restore body is capped by a timeout and degraded to a stderr warning.

Testing

  • Unit tests cover hooks install/uninstall, RestoreHook, ProjectRestoreHook, RunHook, and project restore idempotency.
  • Integration tests exercise real git post-checkout hooks for missing-symlink restore, collision reporting, and idempotent branch switches.
  • make check runs fmt, vet, lint, unit, and integration suites; all green.

@polymorcodeuspolymorcodeus self-assigned this Aug 25, 2026
@polymorcodeus
polymorcodeus merged commit 73bdac7 into mainAug 25, 2026
4 checks passed
@polymorcodeus
polymorcodeus deleted the hooks branch August 25, 2026 16:49
Sign up for freeto 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

@polymorcodeus