Skip to content

feat: implement comprehensive Git hooks support with all 14 standard hooks (#4)#16

Merged
behrangsa merged 4 commits intomasterfrom
feature/comprehensive-git-hooks-support
Jul 28, 2025
Merged

feat: implement comprehensive Git hooks support with all 14 standard hooks (#4)#16
behrangsa merged 4 commits intomasterfrom
feature/comprehensive-git-hooks-support

Conversation

@behrangsa
Copy link
Contributor

Summary

This PR implements comprehensive Git hooks support for Samoid, adding support for all 14 standard Git hooks with proper delegation to the hook runner. This closes issue #4 and provides complete compatibility with all Git workflows.

🎯 Features Implemented

✅ All 14 Standard Git Hooks Supported

  • Complete Coverage: pre-commit, pre-merge-commit, prepare-commit-msg, commit-msg, post-commit, applypatch-msg, pre-applypatch, post-applypatch, pre-rebase, post-rewrite, post-checkout, post-merge, pre-push, pre-auto-gc
  • Proper Delegation: Each hook file delegates to samoid-hook binary using exec samoid-hook "$(basename "$0")" "$@"
  • File Permissions: All hook files maintain proper executable permissions (755)

✅ Custom Hook Script Support

  • User Scripts: Custom scripts in .samoid/scripts/{hook_name} directory
  • Example Scripts: Pre-commit and pre-push example scripts created automatically
  • Clean Architecture: Separation between Git hook delegators and user-customizable scripts

🔧 Technical Implementation

Architecture Changes

.samoid/
├── _/                    # Git hook delegators (created by installer)
│   ├── pre-commit       # #\!/usr/bin/env sh
│   ├── post-commit      # exec samoid-hook "$(basename "$0")" "$@"
│   └── ...              # (all 14 standard hooks)
└── scripts/             # User-customizable hook scripts
    ├── pre-commit       # Example script with format/lint checks
    └── pre-push         # Example script with test runs

Code Changes

  • hooks.rs: Updated create_hook_files() to delegate to samoid-hook binary
  • hooks.rs: Added create_example_hook_scripts() for user script templates
  • hook_runner.rs: Updated to look for user scripts in .samoid/scripts/
  • installer.rs: Integrated example script creation into installation flow
  • main.rs: Fixed test assertion for proper error message matching

🧪 Testing & Quality

Comprehensive Test Coverage

  • 200+ Tests: All unit and integration tests passing
  • Mock-based Testing: Complete isolation using dependency injection pattern
  • Real Execution: Verified functionality with release binaries
  • Error Scenarios: Comprehensive edge case and error condition testing

Verified Functionality

  • Normal Execution: Hook scripts execute correctly when they exist
  • Silent Exit: Graceful handling when hook scripts don't exist
  • Debug Mode: Full tracing with SAMOID=2 for troubleshooting
  • Environment Control: SAMOID=0 properly skips execution
  • Error Handling: Proper error propagation and exit codes

🚀 Integration Status

📋 Acceptance Criteria Completed

All acceptance criteria from issue #4 have been implemented:

  • Support all 14 standard Git hooks (pre-commit, pre-merge-commit, prepare-commit-msg, commit-msg, post-commit, applypatch-msg, pre-applypatch, post-applypatch, pre-rebase, post-rewrite, post-checkout, post-merge, pre-push, pre-auto-gc)
  • Create executable hook files that delegate to runner
  • Maintain hook file permissions (755)
  • Support custom hook scripts in .samoid/ directory

🔄 Breaking Changes

None. This is a purely additive feature that extends existing functionality without changing any existing APIs or behaviors.

📝 Migration Guide

Users upgrading to this version will automatically get:

  1. All 14 standard Git hooks installed when running samoid init
  2. Example hook scripts in .samoid/scripts/ for customization
  3. Full compatibility with existing Git workflows

No manual migration steps required.

Closes #4

behrangsa and others added 4 commits July 28, 2025 10:30
…hooks (#4)

Implements complete support for all standard Git hooks with proper delegation
to the hook runner, maintaining file permissions and supporting custom scripts.

## Features Added
- Support for all 14 standard Git hooks (pre-commit, pre-merge-commit,
  prepare-commit-msg, commit-msg, post-commit, applypatch-msg, pre-applypatch,
  post-applypatch, pre-rebase, post-rewrite, post-checkout, post-merge,
  pre-push, pre-auto-gc)
- Executable hook files (755 permissions) that delegate to samoid-hook binary
- Custom hook script support in .samoid/scripts/ directory with examples
- Clean architecture separating Git hooks from user-customizable scripts

## Implementation Details
- hooks.rs: Updated create_hook_files() to delegate to samoid-hook binary
- hooks.rs: Added create_example_hook_scripts() for user script templates
- hook_runner.rs: Updated to look for user scripts in .samoid/scripts/
- installer.rs: Integrated example script creation into installation flow
- main.rs: Fixed test assertion for proper error message matching

## Architecture
- Git hook delegators: .samoid/_/{hook_name} -> exec samoid-hook
- User hook scripts: .samoid/scripts/{hook_name} (customizable examples)
- Complete integration with existing hook runner from issue #3

## Testing
- 200+ comprehensive unit and integration tests passing
- Real execution verified with release binaries
- Debug mode (SAMOID=2) and environment control (SAMOID=0) tested
- All hook types tested with proper error handling and exit codes

Closes #4

Co-authored-by: Claude Code <code@anthropic.com>
Update workflow documentation to reflect the completion of comprehensive
Git hooks support implementation and track progress on the issue resolution.

This complements the technical implementation with updated process documentation.
Add #[allow(dead_code)] annotations to FileSystem trait methods that are
used through trait implementations but appear unused to the compiler.

These methods (create_dir_all, write, read_to_string, set_permissions)
are actively used in hooks.rs and main.rs through the trait interface,
but the compiler doesn't detect this usage pattern.

Fixes build warnings without changing functionality.
Improve code documentation by adding reason fields to #[allow(dead_code)]
annotations, explaining why these trait methods appear unused but are
actually called through trait objects.

This makes the suppression intent clear for future maintainers and
follows Rust best practices for lint suppression documentation.
@behrangsa behrangsa merged commit e9d5096 into master Jul 28, 2025
@behrangsa behrangsa deleted the feature/comprehensive-git-hooks-support branch July 28, 2025 07:11
behrangsa added a commit that referenced this pull request Jul 31, 2025
…hooks (#4) (#16)

* feat: implement comprehensive Git hooks support with all 14 standard hooks (#4)

Implements complete support for all standard Git hooks with proper delegation
to the hook runner, maintaining file permissions and supporting custom scripts.

## Features Added
- Support for all 14 standard Git hooks (pre-commit, pre-merge-commit,
  prepare-commit-msg, commit-msg, post-commit, applypatch-msg, pre-applypatch,
  post-applypatch, pre-rebase, post-rewrite, post-checkout, post-merge,
  pre-push, pre-auto-gc)
- Executable hook files (755 permissions) that delegate to samoid-hook binary
- Custom hook script support in .samoid/scripts/ directory with examples
- Clean architecture separating Git hooks from user-customizable scripts

## Implementation Details
- hooks.rs: Updated create_hook_files() to delegate to samoid-hook binary
- hooks.rs: Added create_example_hook_scripts() for user script templates
- hook_runner.rs: Updated to look for user scripts in .samoid/scripts/
- installer.rs: Integrated example script creation into installation flow
- main.rs: Fixed test assertion for proper error message matching

## Architecture
- Git hook delegators: .samoid/_/{hook_name} -> exec samoid-hook
- User hook scripts: .samoid/scripts/{hook_name} (customizable examples)
- Complete integration with existing hook runner from issue #3

## Testing
- 200+ comprehensive unit and integration tests passing
- Real execution verified with release binaries
- Debug mode (SAMOID=2) and environment control (SAMOID=0) tested
- All hook types tested with proper error handling and exit codes

Closes #4


* docs: update workflow documentation for issue #4 completion

Update workflow documentation to reflect the completion of comprehensive
Git hooks support implementation and track progress on the issue resolution.

This complements the technical implementation with updated process documentation.

* fix: suppress dead code warnings for trait methods in environment.rs

Add #[allow(dead_code)] annotations to FileSystem trait methods that are
used through trait implementations but appear unused to the compiler.

These methods (create_dir_all, write, read_to_string, set_permissions)
are actively used in hooks.rs and main.rs through the trait interface,
but the compiler doesn't detect this usage pattern.

Fixes build warnings without changing functionality.

* refactor: add explanatory reasons to dead code allow annotations

Improve code documentation by adding reason fields to #[allow(dead_code)]
annotations, explaining why these trait methods appear unused but are
actually called through trait objects.

This makes the suppression intent clear for future maintainers and
follows Rust best practices for lint suppression documentation.

---------
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.

Comprehensive Git Hooks Support

1 participant