feat: add --message-file for commit-msg hook support - #12
Open
agherzan wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
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-fileCLI 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-filebehavior 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.
There was a problem hiding this comment.
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. Preferexpect(...)(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. Preferexpect(...)for a clearer panic message if conversion fails.
!run_check(
Some("all"),
None,
None,
None,
Some(file_path.to_str().unwrap())
),
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.