Skip to content

chore: add pre-push git hook for commit validation - #8

Merged
agherzan merged 1 commit into
canonical:mainfrom
agherzan:ag/hook
Jul 22, 2026
Merged

chore: add pre-push git hook for commit validation#8
agherzan merged 1 commit into
canonical:mainfrom
agherzan:ag/hook

Conversation

@agherzan

@agherzan agherzan commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

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.

@agherzan agherzan self-assigned this Jul 13, 2026
Copilot AI review requested due to automatic review settings July 13, 2026 13:57

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

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-push hook script to validate commit ranges on push.
  • Add task install-githooks to 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.

Comment thread githooks/pre-push
Comment thread githooks/pre-push Outdated
Comment thread Taskfile.yml Outdated
Comment thread githooks/pre-push

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 2 out of 2 changed files in this pull request and generated 4 comments.

Comment thread Taskfile.yml Outdated
Comment thread githooks/pre-push
Comment thread githooks/pre-push
Comment thread githooks/pre-push
@agherzan
agherzan force-pushed the ag/hook branch 2 times, most recently from 0fe96ae to fad2668 Compare July 15, 2026 12:42
@agherzan
agherzan requested a review from Copilot July 15, 2026 12:42

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 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread Taskfile.yml
Comment thread githooks/pre-push
@agherzan
agherzan force-pushed the ag/hook branch 3 times, most recently from e9a25fe to c4b7f4c Compare July 21, 2026 08:58

@pedoch pedoch left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Comment thread githooks/pre-push Outdated
Comment thread Taskfile.yml
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>

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 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-githooks assumes the resolved hooks directory already exists. In some setups (e.g., custom hooksPath, unusual worktree layouts), the directory may be missing and cp will 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. gitlance excludes 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

@agherzan
agherzan merged commit 8d2d504 into canonical:main Jul 22, 2026
4 checks passed
@agherzan
agherzan deleted the ag/hook branch July 22, 2026 20:01
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.

4 participants