Skip to content

feat: add --message-file for commit-msg hook support - #12

Open
agherzan wants to merge 1 commit into
canonical:mainfrom
agherzan:ag/commit-msg
Open

feat: add --message-file for commit-msg hook support#12
agherzan wants to merge 1 commit into
canonical:mainfrom
agherzan:ag/commit-msg

Conversation

@agherzan

Copy link
Copy Markdown
Collaborator

Enables validation of commit messages before the git object exists, allowing gitlance to work as a commit-msg hook. Comment lines are ignored, matching how a commit message is interpreted.

The new mode/argument is mutually exclusive with the ref-based options (--base, --head, --repo, --skip-merge-commits), which are only meaningful when validating existing commits.

@agherzan agherzan self-assigned this Jul 22, 2026
Copilot AI review requested due to automatic review settings July 22, 2026 23:21

Copilot AI left a comment

Copy link
Copy Markdown

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 adds a new --message-file mode to validate a single commit message directly from a file (e.g., .git/COMMIT_EDITMSG), enabling gitlance to run as a commit-msg hook before a commit object exists.

Changes:

  • Add --message-file CLI option and code path to validate a message read from disk, mutually exclusive with ref/range validation options.
  • Add commit-msg git hook script and wire it into task install-githooks.
  • Extend integration/unit tests to cover --message-file behavior and update CLI test harness.

Reviewed changes

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

Show a summary per file
File Description
src/main.rs Adds --message-file mode and ref-based validation branching / updated exit behavior.
src/git.rs Introduces Commit::from_message() and comment-stripping for message-file mode, plus unit tests.
tests/integration_tests.rs Updates integration harness to support message-file mode and adds message-file integration tests.
githooks/commit-msg New hook to run gitlance --message-file during git commit.
Taskfile.yml Installs the new commit-msg hook alongside pre-push.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/git.rs Outdated
Comment thread src/main.rs Outdated
Comment thread src/main.rs

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (2)

tests/integration_tests.rs:379

  • file_path.to_str().unwrap() can panic without context if the path is not valid UTF-8. Prefer expect(...) (as used elsewhere in this file) to make failures actionable.
            !run_check(
                Some("wip-fixup"),
                None,
                None,
                None,
                Some(file_path.to_str().unwrap())
            ),

tests/integration_tests.rs:412

  • file_path.to_str().unwrap() can panic without context if the path is not valid UTF-8. Prefer expect(...) for a clearer panic message if conversion fails.
            !run_check(
                Some("all"),
                None,
                None,
                None,
                Some(file_path.to_str().unwrap())
            ),

Comment thread tests/integration_tests.rs
Comment thread githooks/commit-msg
Enables validation of commit messages before the git object exists,
allowing gitlance to work as a commit-msg hook. Comment lines are
ignored, matching how a commit message is interpreted.

The new mode/argument is mutually exclusive with the ref-based options
(--base, --head, --repo, --skip-merge-commits), which are only
meaningful when validating existing commits.

Signed-off-by: Andrei Gherzan <andrei.gherzan@canonical.com>
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