chore: add pre-push git hook for commit validation - #8
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a local pre-push Git hook to run gitlance commit validation before pushing, plus a Taskfile task to install the hook.
Changes:
- Add
githooks/pre-pushhook script to validate commit ranges on push. - Add
task install-githooksto copy the hook into the local Git hooks directory.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| Taskfile.yml | Adds an install task to place the pre-push hook locally. |
| githooks/pre-push | Implements pre-push validation by running gitlance over the push range. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
agherzan
force-pushed
the
ag/hook
branch
2 times, most recently
from
July 15, 2026 12:42
0fe96ae to
fad2668
Compare
agherzan
force-pushed
the
ag/hook
branch
3 times, most recently
from
July 21, 2026 08:58
e9a25fe to
c4b7f4c
Compare
pedoch
approved these changes
Jul 21, 2026
pedoch
left a comment
Collaborator
There was a problem hiding this comment.
LGTM!
Only caveat I think I see is that you don't validate commits in new branches with not base remote (fresh repo for example). Also seems like it would be more useful as a precommit hook.
josetapadas
reviewed
Jul 22, 2026
josetapadas
reviewed
Jul 22, 2026
Add githooks/pre-push that validates commits before pushing. The hook compares against remote's HEAD for new branches or the merge-base with the remote for existing branches (only checks divergent commits). Add 'task install-githooks' to install the hook locally. Signed-off-by: Andrei Gherzan <andrei.gherzan@canonical.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
Taskfile.yml:30
install-githooksassumes the resolved hooks directory already exists. In some setups (e.g., custom hooksPath, unusual worktree layouts), the directory may be missing andcpwill fail. Create the directory before copying the hook.
- cp githooks/pre-push "{{.HOOKS_DIR}}/"
- chmod +x "{{.HOOKS_DIR}}/pre-push"
- echo "✓ Git hooks installed to {{.HOOKS_DIR}}"
githooks/pre-push:47
- When no merge-base is found for a new branch, the script falls back to the repository root commit as
base.gitlanceexcludes the base commit from its range, so the root commit itself won’t be validated in this fallback path. Prefer using the local remote-tracking HEAD as the base when available (it will be outside the new branch history for unrelated histories, and will still properly exclude already-shared history when related).
# Fall back to root commit if no common ancestor found
if [ -z "$base" ]; then
base=$(git rev-list --max-parents=0 "$local_oid" | head -1)
fi
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.
Add githooks/pre-push that validates commits before pushing.
The hook compares against remote's HEAD for new branches or the
merge-base with the remote for existing branches (only checks
divergent commits).
Add 'task install-githooks' to install the hook locally.