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>
dhruvxvaishnav added a commit to dhruvxvaishnav/gitlance that referenced this pull request Aug 11, 2026
Copying commit-msg and pre-push directly into .git/hooks can replace hooks that contributors already use.

Configure both stages through pre-commit and install its dispatcher from the existing task. Pre-commit preserves prior hooks as legacy hooks and runs them alongside Gitlance, while repeated installation remains idempotent.

Reuse the message-file and not-on-remotes support from canonical#12 and canonical#13. Existing pushes use PRE_COMMIT_FROM_REF and PRE_COMMIT_TO_REF as an exact range, complete-history pushes fall back to unpublished-commit validation, and non-branch refs are skipped.

Add focused integration coverage for each pre-push path and document the local setup and uninstall workflow.

Closes: canonical#9
Signed-off-by: dhruvxvaishnav <dhruvvaishnav687@gmail.com>
dhruvxvaishnav pushed a commit to dhruvxvaishnav/gitlance that referenced this pull request Aug 11, 2026
Copying commit-msg and pre-push directly into .git/hooks can replace
hooks that contributors already use.

Configure both stages through pre-commit and install its dispatcher from
the existing task. Pre-commit preserves prior hooks as legacy hooks,
runs them alongside Gitlance, and keeps repeated installation
idempotent.

Reuse the --message-file and --not-on-remotes modes added by canonical#12 and
canonical#13. The commit-msg stage passes the prepared message file, while the
pre-push stage validates commits reachable from HEAD that are not
present on a remote.

Document the local setup and uninstall workflow.

Closes: canonical#9
Signed-off-by: Dhruv Vaishnav <dhruvvaishav687@gmail.com>
dhruvxvaishnav pushed a commit to dhruvxvaishnav/gitlance that referenced this pull request Aug 11, 2026
Copying commit-msg and pre-push directly into .git/hooks can replace
hooks that contributors already use.

Configure both stages through pre-commit and install its dispatcher from
the existing task. Pre-commit preserves prior hooks as legacy hooks,
runs them alongside Gitlance, and keeps repeated installation
idempotent.

Reuse the --message-file and --not-on-remotes modes added by canonical#12 and
canonical#13. The commit-msg stage passes the prepared message file.

For pre-push, use a small adapter to select the pushed ref from
PRE_COMMIT_TO_REF or PRE_COMMIT_LOCAL_BRANCH. This validates a branch
that is not checked out and skips non-branch refs without changing the
Gitlance CLI.

Document the local setup and uninstall workflow.

Closes: canonical#9
Signed-off-by: Dhruv Vaishnav <dhruvvaishav687@gmail.com>
dhruvxvaishnav pushed a commit to dhruvxvaishnav/gitlance that referenced this pull request Aug 11, 2026
Copying commit-msg and pre-push directly into .git/hooks can replace
hooks that contributors already use.

Configure both stages through pre-commit and install its dispatcher from
the existing task. Pre-commit preserves prior hooks as legacy hooks,
runs them alongside Gitlance, and keeps repeated installation
idempotent.

Reuse the commit-msg hook and the --not-on-remotes mode added by canonical#12 and
canonical#13. Pre-commit passes the prepared message file to the existing hook.

For pre-push, use a small adapter to select the pushed ref from
PRE_COMMIT_TO_REF or PRE_COMMIT_LOCAL_BRANCH. This validates a branch
that is not checked out and skips non-branch refs without changing the
Gitlance CLI.

Document the local setup and uninstall workflow.

Closes: canonical#9
Signed-off-by: Dhruv Vaishnav <dhruvvaishav687@gmail.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