Skip to content

Add validate-submodules pre-commit hook - #11

Merged
kenorb merged 4 commits into
masterfrom
opencode/dispatch-1f30e2-20260429124150
Apr 29, 2026
Merged

kenorb merged 4 commits into
masterfrom
opencode/dispatch-1f30e2-20260429124150

Conversation

@opencode-agent

Copy link
Copy Markdown
Contributor

I've added the validate-submodules hook to the .pre-commit-config.yaml file, ensuring it follows the existing lexicographical sorting convention by placing it after the GitHub-hosted repositories. I also verified the configuration's validity using pre-commit validate-config.

Triggered by workflow_dispatch

New%20session%20-%202026-04-29T12%3A41%3A49.244Z
opencode session  |  github run

Co-authored-by: kenorb <kenorb@users.noreply.github.com>
@sourcery-ai

sourcery-ai Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds a local pre-commit hook to validate Git submodule consistency by running git submodule status, integrated into the existing .pre-commit-config.yaml following the repo ordering conventions.

File-Level Changes

Change Details Files
Introduce a local pre-commit hook to enforce submodule consistency on every run.
  • Append a new repo: local block to .pre-commit-config.yaml after existing GitHub-hosted repositories, preserving lexicographical ordering rules
  • Define a validate-submodules hook that runs bash -c 'git submodule status' with language: system so it relies on the developer's environment Git installation
  • Configure the hook with pass_filenames: false and always_run: true so it runs on every invocation and is not tied to specific changed files
.pre-commit-config.yaml

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've found 2 issues, and left some high level feedback:

  • As written, bash -c 'git submodule status' will always exit 0 even if submodules are modified or uninitialized, so if the goal is to enforce consistency you may want a small script that inspects the output (e.g., fails on lines starting with - or +) instead of just running the command directly.
  • Using language: system with bash -c couples the hook to Bash being available; consider switching to language: script and checking in a small, executable script to make the hook more portable and easier to evolve.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- As written, `bash -c 'git submodule status'` will always exit 0 even if submodules are modified or uninitialized, so if the goal is to enforce consistency you may want a small script that inspects the output (e.g., fails on lines starting with `-` or `+`) instead of just running the command directly.
- Using `language: system` with `bash -c` couples the hook to Bash being available; consider switching to `language: script` and checking in a small, executable script to make the hook more portable and easier to evolve.

## Individual Comments

### Comment 1
<location path=".pre-commit-config.yaml" line_range="101-103" />
<code_context>
       - id: detect-secrets
+  - repo: local
+    hooks:
+      - id: validate-submodules
+        name: Validate Submodule Consistency
+        entry: bash -c 'git submodule status'
+        language: system
+        pass_filenames: false
</code_context>
<issue_to_address>
**issue (bug_risk):** Current command likely never fails, so the hook won’t actually enforce consistency.

`git submodule status` exits 0 in most cases and only prints the state, so the hook won’t fail even if submodules are uninitialized or out of date. To actually enforce consistency, use a command that returns non-zero on problems (e.g., `git submodule status --recursive --fail` in Git ≥2.40, or a custom script that checks for unexpected submodule commits).
</issue_to_address>

### Comment 2
<location path=".pre-commit-config.yaml" line_range="103" />
<code_context>
+    hooks:
+      - id: validate-submodules
+        name: Validate Submodule Consistency
+        entry: bash -c 'git submodule status'
+        language: system
+        pass_filenames: false
</code_context>
<issue_to_address>
**suggestion:** Avoid `bash -c` when a direct entry and arguments would work.

For example, configure this as `entry: git` with `args: [submodule, status, --recursive]`. This avoids quoting issues and makes the hook’s behavior clearer and more portable.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread .pre-commit-config.yaml Outdated
Comment thread .pre-commit-config.yaml Outdated
@kenorb

kenorb commented Apr 29, 2026

Copy link
Copy Markdown
Member

/co Address PR comments.

Co-authored-by: kenorb <kenorb@users.noreply.github.com>
@opencode-agent

Copy link
Copy Markdown
Contributor Author

I have addressed the PR comments by implementing a more robust submodule validation script and updating the pre-commit configuration.

Changes made:

  • Created .github/scripts/validate-submodules.sh:
    • This script runs git submodule status --recursive.
    • It correctly fails (exit code 1) if any submodules are uninitialized (-), modified (+), or have conflicts (U).
    • It provides descriptive error messages when consistency checks fail.
  • Updated .pre-commit-config.yaml:
    • Changed language from system to script for the validate-submodules hook, as suggested by the reviewer.
    • Set the entry to point to the new script.
    • Ensured the script is executable.

The configuration has been validated using pre-commit validate-config and the hook was tested locally using pre-commit run validate-submodules --all-files, where it passed successfully.

New%20session%20-%202026-04-29T12%3A48%3A34.737Z
opencode session  |  github run

@kenorb

kenorb commented Apr 29, 2026

Copy link
Copy Markdown
Member

/co I prefer previous version without external script. Just improve the hook, but without additional script.

Co-authored-by: kenorb <kenorb@users.noreply.github.com>
@opencode-agent

Copy link
Copy Markdown
Contributor Author

initialized, modified, or in conflict, and I've removed the .github/scripts/validate-submodules.sh script.

Changes:

  • .pre-commit-config.yaml: Replaced the script entry with bash -c "! git submodule status --recursive | grep -q '^[+U-]'" and changed the language to system.
  • .github/scripts/validate-submodules.sh: Deleted the script.

The configuration has been verified with pre-commit validate-config.

New%20session%20-%202026-04-29T13%3A00%3A51.836Z
opencode session  |  github run

@kenorb
kenorb merged commit db14c69 into master Apr 29, 2026
6 of 7 checks passed
@kenorb
kenorb deleted the opencode/dispatch-1f30e2-20260429124150 branch April 29, 2026 13:08
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.

1 participant