Skip to content

feat(hooks): Add Git hooks installation system#248

Merged
DrunkOnJava merged 1 commit intomainfrom
feat/update-pre-commit-hook
Jul 31, 2025
Merged

feat(hooks): Add Git hooks installation system#248
DrunkOnJava merged 1 commit intomainfrom
feat/update-pre-commit-hook

Conversation

@DrunkOnJava
Copy link
Owner

🪝 Git Hooks Installation System

This PR adds a system for managing Git hooks as part of the hybrid workflow.

What this adds:

  • Git hooks templates in scripts/git-hooks/:
    • pre-commit - Enforces commit standards (30 files, 800 lines)
    • post-commit - Auto-pushes for single source of truth
  • Installation script (scripts/install-hooks.sh):
    • Installs hooks from templates
    • Backs up existing hooks
    • Provides clear feedback

Pre-commit hook updates:

  • Added hybrid workflow documentation
  • Shows branch-specific hints for feature branches
  • Maintains all existing validations:
    • Size limits (30 files, 800 lines)
    • Protected file checks
    • Duplicate type prevention
    • Commit frequency reminders

Installation:

# Install all hooks
./scripts/install-hooks.sh

# Hooks can be bypassed if needed
git commit --no-verify

Why this matters:

  • Consistency: All developers use the same hooks
  • Version control: Hooks are tracked and reviewed
  • Easy updates: One command to update hooks
  • Onboarding: New developers get hooks automatically

This is Part 5 of 5 of the hybrid workflow implementation.

Summary

With this PR, the hybrid workflow implementation is complete:

  1. ✅ Nightly rebase workflow (PR feat(workflow): Add nightly dev-to-main rebase automation #244)
  2. ✅ PR management workflow (PR feat(workflow): Add PR management automation #245)
  3. ✅ Automation scripts (PR feat(scripts): Add hybrid workflow automation scripts #246)
  4. ✅ Documentation (PR docs: Add comprehensive hybrid workflow documentation #247)
  5. ✅ Git hooks system (This PR)

Git hooks ensure consistent development practices across the team.

Copilot AI review requested due to automatic review settings July 31, 2025 22:24
@github-actions
Copy link

🔍 PR Validation Results

Build Status: ❌ Failed
SwiftLint: ⚠️ Issues found
Project Structure: ❌ Issues found
Compilation: ❌ Failed


This comment was automatically generated by the PR validation workflow.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements a Git hooks installation system as the final component of the hybrid workflow implementation, providing automated enforcement of commit standards and seamless integration with the development process.

Key changes:

  • Installation script for managing Git hooks templates and deployment
  • Pre-commit hook enforcing Claude Code standards with hybrid workflow integration
  • Post-commit hook for automatic pushing to maintain single source of truth

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
scripts/install-hooks.sh Installation script that deploys hooks from templates with backup functionality
scripts/git-hooks/pre-commit Pre-commit hook enforcing commit size limits, protected files, and duplicate type checking
scripts/git-hooks/post-commit Post-commit hook for automatic pushing and Git LFS integration

DUPLICATES=""
for file in $STAGED_SWIFT_FILES; do
# Extract public type names from staged content
git show ":$file" 2>/dev/null | grep -E "^public (class|struct|enum|protocol|actor) " | \
Copy link

Copilot AI Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The duplicate type check may fail when processing new files that don't exist in the current commit. Consider using git diff --cached to get staged content instead of git show ":$file".

Suggested change
git show ":$file" 2>/dev/null | grep -E "^public (class|struct|enum|protocol|actor) " | \
git diff --cached -- "$file" 2>/dev/null | grep -E "^public (class|struct|enum|protocol|actor) " | \

Copilot uses AI. Check for mistakes.
echo -e "${GREEN}✅ Successfully pushed $BRANCH to origin${NC}"

# Update sync timestamp
SYNC_FILE=".github/sync-status/local-push.json"
Copy link

Copilot AI Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sync file is created in the working directory but never committed or pushed. This could lead to untracked files accumulating in the repository. Consider using a different location outside the git repository or adding this to .gitignore.

Copilot uses AI. Check for mistakes.
sed -E 's/^public (class|struct|enum|protocol|actor) ([A-Za-z0-9_]+).*/\2/' | \
while read -r type_name; do
# Check if this type already exists in other files
existing=$(git grep -l "^public \(class\|struct\|enum\|protocol\|actor\) $type_name" -- '*.swift' | grep -v "^$file:")
Copy link

Copilot AI Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The grep pattern uses ^$file: but git grep -l returns only filenames, not filename: format. This grep filter will never match and won't properly exclude the current file from duplicate detection.

Suggested change
existing=$(git grep -l "^public \(class\|struct\|enum\|protocol\|actor\) $type_name" -- '*.swift' | grep -v "^$file:")
existing=$(git grep -l "^public \(class\|struct\|enum\|protocol\|actor\) $type_name" -- '*.swift' | awk -v current_file="$file" '$0 != current_file')

Copilot uses AI. Check for mistakes.

if [ -n "$STAGED_SWIFT_FILES" ]; then
# Check for new duplicate types in staged files
DUPLICATES=""
Copy link

Copilot AI Jul 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The DUPLICATES variable is set within a while loop subshell and won't be accessible outside the loop. This means the duplicate detection check at line 106 will always pass even when duplicates are found.

Suggested change
DUPLICATES=""
DUPLICATES=()

Copilot uses AI. Check for mistakes.
DrunkOnJava added a commit that referenced this pull request Jul 31, 2025
Update PR validation workflow to gracefully handle PRs that contain
no Swift files (like workflow-only or documentation PRs):
- Check for Swift files before running SwiftLint
- Skip Xcode build steps for non-Swift PRs
- Make Swift-specific checks conditional

This fixes CI failures for PRs #244-#248 which only contain
workflow files and scripts.

Co-authored-by: Claude <claude@anthropic.com>
DrunkOnJava added a commit that referenced this pull request Jul 31, 2025
Update PR validation workflow to gracefully handle PRs that contain
no Swift files (like workflow-only or documentation PRs):
- Check for Swift files before running SwiftLint
- Skip Xcode build steps for non-Swift PRs
- Make Swift-specific checks conditional

This fixes CI failures for PRs #244-#248 which only contain
workflow files and scripts.

Co-authored-by: Claude <claude@anthropic.com>
DrunkOnJava added a commit that referenced this pull request Jul 31, 2025
- Check if PR contains Swift file changes before running SwiftLint
- Skip Swift-specific checks (TODO/FIXME, security) for non-Swift PRs
- Fixes CI failures on workflow-only PRs like #244-#248

This properly handles PRs that only modify workflows, scripts, or
documentation without triggering Swift-related validations.
DrunkOnJava added a commit that referenced this pull request Jul 31, 2025
* fix(ci): Only run Swift checks on PRs with Swift changes

- Check if PR contains Swift file changes before running SwiftLint
- Skip Swift-specific checks (TODO/FIXME, security) for non-Swift PRs
- Fixes CI failures on workflow-only PRs like #244-#248

This properly handles PRs that only modify workflows, scripts, or
documentation without triggering Swift-related validations.

* fix(ci): Also check Swift changes for project generation step

The check_swift step needs to use the has_swift_changes output to
avoid trying to generate Xcode projects for non-Swift PRs.
Add system for managing and installing Git hooks:
- Pre-commit hook with updated limits (30 files, 800 lines)
- Post-commit auto-push hook for single source of truth
- Install script for easy setup
- Hooks stored in version control for consistency

Changes to pre-commit hook:
- Updated documentation to mention hybrid workflow
- Added branch awareness (shows hint for feature branches)
- Maintained all existing checks (size, protected files, duplicates)

This ensures all developers use the same hooks and can easily
update them when the workflow evolves.

Part 5 of the hybrid workflow implementation.

Co-authored-by: Claude <claude@anthropic.com>
@DrunkOnJava DrunkOnJava force-pushed the feat/update-pre-commit-hook branch from af3e74e to 54add12 Compare July 31, 2025 23:11
@github-actions
Copy link

🔍 PR Validation Results

Build Status: ✅ Passed
SwiftLint: ⚠️ Issues found
Project Structure: ❌ Issues found
Compilation: ❌ Failed


This comment was automatically generated by the PR validation workflow.

@DrunkOnJava DrunkOnJava merged commit 486f34c into main Jul 31, 2025
2 of 4 checks passed
@DrunkOnJava DrunkOnJava deleted the feat/update-pre-commit-hook branch July 31, 2025 23:13
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.

2 participants