Skip to content

Future: Replace bash hook scripts with thin CLI shims #17

@ichoosetoaccept

Description

@ichoosetoaccept

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:

  1. Reduce surface area — one code path instead of two
  2. Improve testability — Rust unit tests instead of shell script integration tests
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions