Summary
Replace the self-contained bash scripts currently installed in .git/hooks/ with thin shims that delegate to but hook CLI subcommands:
#!/bin/sh
exec but hook pre-commit "$@"
Motivation
The current managed hooks duplicate logic that already exists in the Rust but hook subcommands:
- Branch detection (
git name-rev / git symbolic-ref in bash vs gix ref resolution in Rust)
- Guard messages (hardcoded strings in bash vs structured output in Rust)
- User hook chaining (bash
exec of backup file vs potential Rust-level chaining)
- Post-checkout cleanup (bash
rm of hook files vs Rust uninstall_managed_hooks)
Unifying these would:
- Reduce surface area — one code path instead of two
- Improve testability — Rust unit tests instead of shell script integration tests
- Enable richer behavior — structured errors, logging, JSON output from hooks
Requirements
- Add
--managed mode to but hook pre-commit/post-checkout/pre-push subcommands that includes:
- User hook chaining (run
<hook>-user backup before/after the guard)
- Post-checkout cleanup (uninstall managed hooks when leaving workspace)
- Keep bash fallback for Desktop-only users who may not have the
but CLI installed
- Detect whether
but is available at install time and choose shim vs full script accordingly
Context
Discussed during fork PR #6 review. See "Future work: thin-shim hooks" section in that PR description.
Related: upstream PR gitbutlerapp/gitbutler#12980
Summary
Replace the self-contained bash scripts currently installed in
.git/hooks/with thin shims that delegate tobut hookCLI subcommands:Motivation
The current managed hooks duplicate logic that already exists in the Rust
but hooksubcommands:git name-rev/git symbolic-refin bash vsgixref resolution in Rust)execof backup file vs potential Rust-level chaining)rmof hook files vs Rustuninstall_managed_hooks)Unifying these would:
Requirements
--managedmode tobut hook pre-commit/post-checkout/pre-pushsubcommands that includes:<hook>-userbackup before/after the guard)butCLI installedbutis available at install time and choose shim vs full script accordinglyContext
Discussed during fork PR #6 review. See "Future work: thin-shim hooks" section in that PR description.
Related: upstream PR gitbutlerapp/gitbutler#12980