Skip to content

Install Git Pre-Commit Hooks for Copilot Agent #121

@josecelano

Description

@josecelano

Parent Epic: #112 - Refactor and Improve E2E Test Execution
Depends On: #120 - Configure GitHub Copilot Agent Environment (Issue 1-4)

Overview

Install Git pre-commit hooks in the Copilot agent's environment to enforce pre-commit checks deterministically. This ensures the agent cannot commit code without running linting checks, even if the agent forgets or ignores the instruction in .github/copilot-instructions.md.

Problem

Previous attempts to instruct the Copilot agent to run pre-commit checks via .github/copilot-instructions.md were not reliable. The agent sometimes:

  • Forgot to run checks before committing
  • Ignored the instructions
  • Committed code that failed linting

Solution: Use Git hooks to enforce checks mechanistically, not instructionally.

Objectives

  • Create symlink from .git/hooks/pre-commit to ./scripts/pre-commit.sh
  • Install hook in Copilot setup workflow
  • Verify hook works correctly (blocks bad commits)
  • Document the hook installation process

Implementation Approach

Use Symlink (NOT Wrapper Script):

ln -sf ../../scripts/pre-commit.sh .git/hooks/pre-commit

Why Symlink:

  • ✅ Simple - no wrapper script needed
  • ✅ Always up-to-date - changes to script are immediately reflected
  • ✅ Single source of truth - ./scripts/pre-commit.sh
  • ✅ Easy to verify - readlink .git/hooks/pre-commit

Workflow Integration

Add to .github/workflows/copilot-setup-steps.yml:

- name: Install Git pre-commit hooks
  run: |
    # Create symlink to enforce pre-commit checks
    ln -sf ../../scripts/pre-commit.sh .git/hooks/pre-commit
    chmod +x .git/hooks/pre-commit
    
    # Verify hook is installed
    if [ -L .git/hooks/pre-commit ]; then
      echo "✅ Pre-commit hook installed successfully"
      readlink .git/hooks/pre-commit
    else
      echo "❌ Failed to install pre-commit hook"
      exit 1
    fi

Acceptance Criteria

  • Pre-commit checks pass
  • Hook installation added to Copilot setup workflow
  • Hook successfully blocks commits that fail checks
  • Hook is verified during workflow execution
  • Documentation updated

Time Estimate

2-3 hours

Related Documentation

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions