Skip to content

Add CLI Support for Setting Up Pre-Commit Hook #3

@randilt

Description

@randilt

Enhance the tool with a --init flag to automate setting up the commit-msg hook, including:

  1. Git Directory Validation – Check if the tool is run inside a valid Git repository.
  2. Existing Hook Detection – If a commit-msg hook already exists, prompt the user to modify or replace it.
  3. Automatic Hook Setup – If no existing hook, create one linking to the linter.
  4. Configurable Options – Allow users to choose custom configurations during setup or by passing --config flag.
  5. Helpful Messages – Provide clear output on setup success or failure.

More info:

To check linting of the current commit message the commit-msg hook should be modified with the following:

#!/bin/sh
commit_msg_file="$1"

# Run the linter with the commit message file
git-commit-linter lint-file "$commit_msg_file" || exit 1

Currently this needs to be modified manually, with this new implementation this configuration will be automated.

Example Command: git-commit-linter --init

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