Skip to content

Add repository-specific hooks support#2

Merged
gage-halverson-fetch merged 1 commit intomainfrom
feature/hooks-support
Feb 4, 2026
Merged

Add repository-specific hooks support#2
gage-halverson-fetch merged 1 commit intomainfrom
feature/hooks-support

Conversation

@gage-halverson-fetch
Copy link
Collaborator

Summary

Adds a hooks system that allows repositories to define custom scripts executed during sprout operations.

  • HooksService discovers and executes hooks from .sprout/hooks/ within each repository
  • post-prune hook runs after each worktree is removed, receiving environment variables:
    • SPROUT_WORKTREE_PATH - path of the removed worktree
    • SPROUT_BRANCH - branch name that was pruned
    • SPROUT_REPO_ROOT - root directory of the main repository
  • Dry-run mode shows which hooks would run
  • Verbose flag (-v) for detailed hook execution output

Example Use Case

Clean up Xcode DerivedData when pruning worktrees from iOS projects:

# .sprout/hooks/post-prune
#!/bin/bash
for dir in ~/Library/Developer/Xcode/DerivedData/Fetch-*/; do
  workspace=$(plutil -extract WorkspacePath raw "$dir/info.plist" 2>/dev/null)
  if [[ "$workspace" == *"$SPROUT_WORKTREE_PATH"* ]]; then
    rm -rf "$dir"
    echo "Cleaned: $(basename $dir)"
  fi
done

Test plan

  • Build passes
  • Dry-run shows "Would run post-prune hook" when hook exists
  • Hook executes after worktree removal
  • Non-executable hooks show warning with chmod instructions

🤖 Generated with Claude Code

Introduces a hooks system that allows repos to define custom scripts
executed during prune operations. Hooks are placed in .sprout/hooks/
within each repository.

Features:
- HooksService to discover and execute hooks from .sprout/hooks/
- post-prune hook runs after each worktree is removed
- Environment variables passed to hooks: SPROUT_WORKTREE_PATH,
  SPROUT_BRANCH, SPROUT_REPO_ROOT
- Dry-run mode shows which hooks would run
- Verbose flag (-v) for detailed hook execution output

Example use case: Clean up Xcode DerivedData when pruning worktrees
from iOS projects.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@gage-halverson-fetch gage-halverson-fetch merged commit 635a8ee into main Feb 4, 2026
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