Skip to content

fix(hooks): support linked worktree commits - #159

Open
marlon-costa-dc wants to merge 1 commit into
mainfrom
bead/mcb-o96i-16-hook-commit
Open

fix(hooks): support linked worktree commits#159
marlon-costa-dc wants to merge 1 commit into
mainfrom
bead/mcb-o96i-16-hook-commit

Conversation

@marlon-costa-dc

Copy link
Copy Markdown
Collaborator

No description provided.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • Added hook validation to the standard check workflow.
    • Added commands to resolve Git hook locations and install pre-commit hooks automatically.
    • Hook installation now supports linked worktrees through the configured hooks directory.
  • Bug Fixes

    • Updated commit processing so commit checks run before files are staged.
    • Improved pre-commit hook setup and removed reliance on outdated installation behavior.
  • Tests

    • Added automated coverage for hook installation in primary repositories and linked worktrees.

Walkthrough

The change centralizes Git hook installation through mcb.sh, adds worktree-aware hook tests to the check phases, updates setup wiring, and applies the commit gate before optional staging.

Changes

Hooks and commit flow

Layer / File(s) Summary
Centralized hook installation
scripts/lib/mcb.sh, makefiles/dispatch.mk, scripts/hooks/pre-commit
Git hook directories are resolved through git rev-parse; setup invokes install-hooks, which copies and enables the canonical pre-commit hook.
Hook check integration
Makefile, makefiles/dispatch.mk, scripts/lib/tests/test-hooks.sh
The hooks phase is added to make check, dispatches to the new test harness, and validates installation across linked worktrees.
Commit gate ordering
makefiles/dispatch.mk
The commit gate now runs before conditional staging of specified files.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: marlonsc

Poem

I’m a bunny with hooks in a row,
Installing them where Git says to go.
Worktrees all share the right path,
Gates run before staging’s bath.
Hop, commit, and checks all glow!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive No pull request description was provided, so relevance cannot be meaningfully evaluated. Add a brief PR description summarizing the hook and worktree changes.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title matches the main change: adding hook support for linked worktree commits.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch bead/mcb-o96i-16-hook-commit

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@qodo-code-review

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Support pre-commit hooks in linked Git worktrees

🐞 Bug fix 🧪 Tests ⚙️ Configuration changes 🕐 20-40 Minutes

Grey Divider

AI Description

• Resolve hook installation through Git’s shared directory for linked worktrees.
• Route setup through the canonical installer and expose a focused hook check.
• Test shared installation and gate dry-run commits before staging requested files.
Diagram

sequenceDiagram
  actor Dev as Developer
  participant Make as Make setup
  participant MCB as Hook installer
  participant Git as Git metadata
  participant Hooks as Shared hooks
  Dev->>Make: setup hooks
  Make->>MCB: install-hooks
  MCB->>Git: resolve common dir
  Git-->>MCB: absolute path
  MCB->>Hooks: copy and chmod
  MCB-->>Dev: installed path
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Configure core.hooksPath
  • ➕ Runs the checked-in hook directly without copying it.
  • ➕ Naturally shares one hook path across linked worktrees.
  • ➕ Hook changes become available immediately after checkout.
  • ➖ Mutates repository-local Git configuration.
  • ➖ Can conflict with developers’ existing hooksPath configuration.
  • ➖ Couples hook execution directly to the worktree checkout layout.

Recommendation: Keep the PR’s Git-common-directory installer. It minimally corrects linked-worktree behavior while preserving the existing explicit setup workflow and avoiding Git configuration conflicts. Installing separately under each worktree Git directory was also considered but dismissed because Git hooks are shared repository metadata.

Files changed (5) +68 / -6

Bug fix (2) +24 / -3
dispatch.mkCentralize hook setup and protect commit dry-runs +4/-3

Centralize hook setup and protect commit dry-runs

• Adds the hook fixture check and routes setup through the canonical 'mcb.sh install-hooks' command. It also moves the commit mutation gate before 'git add', preventing dry-runs from staging files.

makefiles/dispatch.mk

mcb.shInstall hooks into the shared Git common directory +20/-0

Install hooks into the shared Git common directory

• Adds commands for resolving the absolute Git common hooks directory and installing an executable pre-commit hook there. This makes installation work consistently from primary and linked worktrees.

scripts/lib/mcb.sh

Tests (1) +41 / -0
test-hooks.shVerify hook installation across linked worktrees +41/-0

Verify hook installation across linked worktrees

• Creates temporary primary and linked worktrees, verifies they resolve the same common hooks directory, and tests hook content and executability. It also guards against installing a hook that references the removed 'make boot' target.

scripts/lib/tests/test-hooks.sh

Documentation (1) +2 / -2
pre-commitClarify the current pre-commit gate behavior +2/-2

Clarify the current pre-commit gate behavior

• Updates the header documentation to describe the canonical commit gates and confirm that the hook does not invoke removed Make targets.

scripts/hooks/pre-commit

Other (1) +1 / -1
MakefileExpose hook fixtures through the check command +1/-1

Expose hook fixtures through the check command

• Adds 'hooks' to the supported 'make check WHAT=...' phases so the focused shell fixture is discoverable and dispatchable.

Makefile

@qodo-code-review

qodo-code-review Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (3) 📘 Rule violations (2) 📜 Skill insights (0)

Context used
✅ Compliance rules (platform): 36 rules

Grey Divider


Action required

1. git add errors swallowed 📘 Rule violation ☼ Reliability ⭐ New
Description
The && git add $(FILES) || true chain converts a failed git add into success, allowing `git
commit` to proceed with incomplete or unintended staged content. This silently hides a fallible
operation in the modified commit path.
Code

makefiles/dispatch.mk[206]

+  commit)     $(call require_var,MSG); bash $(MCB_SH) files-safe "$(FILES)"; $(call gate,commit); [ -n "$(FILES)" ] && git add $(FILES) || true; git commit -m "$(MSG)" ;; \
Evidence
PR Compliance ID 1208751 prohibits silently discarded errors, explicitly including || true-style
handling. On the changed line, a non-empty FILES value followed by a failed git add reaches `||
true, after which git commit` still executes.

Rule 1208751: Errors must not be silently swallowed or hidden
makefiles/dispatch.mk[206-206]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The commit dispatch silently ignores `git add` failures because `|| true` applies to the complete `test && git add` chain.

## Issue Context
An empty `FILES` value should remain valid, but a non-empty value whose `git add` fails must stop the command before `git commit` executes. Use an explicit conditional so only the empty-value case is skipped.

## Fix Focus Areas
- makefiles/dispatch.mk[206-206]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. Configured hook paths ignored 🐞 Bug ≡ Correctness
Description
mcb_git_hooks_dir always installs under <git-common-dir>/hooks, so repositories with a
non-default core.hooksPath report successful installation into a directory Git does not execute.
This silently disables the documented pre-commit enforcement for those repositories.
Code

scripts/lib/mcb.sh[R57-59]

+  common_dir="$(git -C "$repo" rev-parse --path-format=absolute --git-common-dir)" \
+    || mcb_die "$EX_PREREQ" "nao foi possivel resolver o diretorio Git comum de '$repo'"
+  printf '%s/hooks\n' "$common_dir"
Evidence
The installer derives and copies exclusively to the common Git directory, while the project contract
says setup provides mechanical no-bypass enforcement. The test derives the same expected path and
therefore cannot detect an alternate configured hooks directory.

scripts/lib/mcb.sh[54-69]
scripts/lib/tests/test-hooks.sh[17-35]
AGENTS.md[185-190]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Hook installation constructs `<git-common-dir>/hooks`, ignoring repositories that configure an alternate `core.hooksPath`. Resolve the effective hooks location through Git so the installed hook is actually executed.

## Issue Context
The installer reports success after copying to the constructed directory, while project documentation describes the hook as mechanical enforcement. Extend tests to cover a configured hook path as well as primary and linked worktrees.

## Fix Focus Areas
- scripts/lib/mcb.sh[54-69]
- scripts/lib/tests/test-hooks.sh[17-35]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended

3. Documented install breaks worktrees 🐞 Bug ≡ Correctness ⭐ New
Description
The new worktree-safe installer is used by make setup, but the operational guide still instructs
users to copy into .git/hooks. Because .git is a file in linked worktrees, users following those
instructions cannot install the pre-commit hook there.
Code

makefiles/dispatch.mk[251]

+  hooks)     bash $(MCB_SH) install-hooks ;; \
Evidence
The changed setup command uses the new resolver, and the regression test confirms that linked
worktrees have a .git file. Both operational installation examples bypass this resolver and treat
.git/hooks as a directory, so those commands fail in the exact environment this PR adds support
for.

makefiles/dispatch.mk[248-254]
scripts/lib/tests/test-hooks.sh[17-26]
docs/operations/CI_RELEASE.md[52-60]
docs/operations/CI_RELEASE.md[654-660]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The operational guide still installs the pre-commit hook by copying into `.git/hooks`. That path is invalid in linked worktrees, where `.git` is a file; update both documented installation examples to invoke the new worktree-aware installer, preferably `make setup WHAT=hooks`.

## Issue Context
The setup dispatch now delegates to `mcb.sh install-hooks`, which resolves the shared Git hooks directory. The linked-worktree test confirms that `.git` is a file in that environment.

## Fix Focus Areas
- docs/operations/CI_RELEASE.md[52-60]
- docs/operations/CI_RELEASE.md[654-660]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


4. Hook regression test skips CI 🐞 Bug ☼ Reliability
Description
The new test is reachable only through WHAT=hooks; WHAT=all, which backs make ci, does not
invoke it, and the CI workflow has no separate hooks-test step. Linked-worktree hook regressions can
therefore merge without this test running.
Code

makefiles/dispatch.mk[78]

+  hooks)    bash scripts/lib/tests/test-hooks.sh ;; \
Evidence
The dispatch file adds only a standalone hooks arm, while its all arm omits that command. `make
ci delegates to WHAT=all`, and the inspected CI workflow invokes lint and audit checks without
invoking WHAT=hooks.

makefiles/dispatch.mk[68-80]
Makefile[68-68]
.github/workflows/ci.yml[116-166]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The linked-worktree hook regression test is exposed as a standalone check but is absent from the canonical CI execution paths. Integrate it into `WHAT=all` or add an explicit CI step/job.

## Issue Context
`make ci` delegates to `make check WHAT=all`, whose dispatch arm excludes the hooks test. The current workflow invokes no standalone `WHAT=hooks` check.

## Fix Focus Areas
- makefiles/dispatch.mk[68-80]
- Makefile[68-68]
- .github/workflows/ci.yml[116-166]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


5. hooks missing from command docs 📘 Rule violation ≡ Correctness
Description
The Makefile adds hooks to the supported make check WHAT=... options, but the repository’s
static command reference still omits it. Developers relying on AGENTS.md therefore receive an
incomplete list of executable check phases.
Code

Makefile[39]

+WHATS_check   := fmt lint validate audit udeps coverage qlty hooks all
Evidence
PR Compliance ID 1207215 requires static build and run documentation to remain synchronized with
executable Makefile options. Makefile now includes hooks in WHATS_check, while the command
reference in AGENTS.md still lists only fmt|lint|validate|audit|udeps|coverage|qlty|all.

Rule 1207215: Keep static configuration documents in sync with executable build configuration files
Makefile[39-39]
AGENTS.md[143-150]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new `make check WHAT=hooks` phase is absent from the static command reference.

## Issue Context
`WHATS_check` now exposes `hooks`, while `AGENTS.md` presents an explicit list of supported `WHAT` values without it.

## Fix Focus Areas
- Makefile[39-39]
- AGENTS.md[143-150]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

To customize comments, go to the Qodo configuration screen, or learn more in the docs.

Previous review results

Review updated until commit b081ab9 ⚖️ Balanced

Results up to commit b081ab9 ⚖️ Balanced


🐞 Bugs (2) 📘 Rule violations (1) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)


Action required
1. Configured hook paths ignored 🐞 Bug ≡ Correctness
Description
mcb_git_hooks_dir always installs under <git-common-dir>/hooks, so repositories with a
non-default core.hooksPath report successful installation into a directory Git does not execute.
This silently disables the documented pre-commit enforcement for those repositories.
Code

scripts/lib/mcb.sh[R57-59]

+  common_dir="$(git -C "$repo" rev-parse --path-format=absolute --git-common-dir)" \
+    || mcb_die "$EX_PREREQ" "nao foi possivel resolver o diretorio Git comum de '$repo'"
+  printf '%s/hooks\n' "$common_dir"
Evidence
The installer derives and copies exclusively to the common Git directory, while the project contract
says setup provides mechanical no-bypass enforcement. The test derives the same expected path and
therefore cannot detect an alternate configured hooks directory.

scripts/lib/mcb.sh[54-69]
scripts/lib/tests/test-hooks.sh[17-35]
AGENTS.md[185-190]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
Hook installation constructs `<git-common-dir>/hooks`, ignoring repositories that configure an alternate `core.hooksPath`. Resolve the effective hooks location through Git so the installed hook is actually executed.

## Issue Context
The installer reports success after copying to the constructed directory, while project documentation describes the hook as mechanical enforcement. Extend tests to cover a configured hook path as well as primary and linked worktrees.

## Fix Focus Areas
- scripts/lib/mcb.sh[54-69]
- scripts/lib/tests/test-hooks.sh[17-35]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools



Remediation recommended
2. hooks missing from command docs 📘 Rule violation ≡ Correctness
Description
The Makefile adds hooks to the supported make check WHAT=... options, but the repository’s
static command reference still omits it. Developers relying on AGENTS.md therefore receive an
incomplete list of executable check phases.
Code

Makefile[39]

+WHATS_check   := fmt lint validate audit udeps coverage qlty hooks all
Evidence
PR Compliance ID 1207215 requires static build and run documentation to remain synchronized with
executable Makefile options. Makefile now includes hooks in WHATS_check, while the command
reference in AGENTS.md still lists only fmt|lint|validate|audit|udeps|coverage|qlty|all.

Rule 1207215: Keep static configuration documents in sync with executable build configuration files
Makefile[39-39]
AGENTS.md[143-150]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The new `make check WHAT=hooks` phase is absent from the static command reference.

## Issue Context
`WHATS_check` now exposes `hooks`, while `AGENTS.md` presents an explicit list of supported `WHAT` values without it.

## Fix Focus Areas
- Makefile[39-39]
- AGENTS.md[143-150]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Hook regression test skips CI 🐞 Bug ☼ Reliability
Description
The new test is reachable only through WHAT=hooks; WHAT=all, which backs make ci, does not
invoke it, and the CI workflow has no separate hooks-test step. Linked-worktree hook regressions can
therefore merge without this test running.
Code

makefiles/dispatch.mk[78]

+  hooks)    bash scripts/lib/tests/test-hooks.sh ;; \
Evidence
The dispatch file adds only a standalone hooks arm, while its all arm omits that command. `make
ci delegates to WHAT=all`, and the inspected CI workflow invokes lint and audit checks without
invoking WHAT=hooks.

makefiles/dispatch.mk[68-80]
Makefile[68-68]
.github/workflows/ci.yml[116-166]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
The linked-worktree hook regression test is exposed as a standalone check but is absent from the canonical CI execution paths. Integrate it into `WHAT=all` or add an explicit CI step/job.

## Issue Context
`make ci` delegates to `make check WHAT=all`, whose dispatch arm excludes the hooks test. The current workflow invokes no standalone `WHAT=hooks` check.

## Fix Focus Areas
- makefiles/dispatch.mk[68-80]
- Makefile[68-68]
- .github/workflows/ci.yml[116-166]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Qodo Logo

Comment thread Makefile

# --- WHATS_<verb> phase SSOT (drives sub-help + error arms) -------------------
WHATS_check := fmt lint validate audit udeps coverage qlty all
WHATS_check := fmt lint validate audit udeps coverage qlty hooks all

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.

Remediation recommended

1. hooks missing from command docs 📘 Rule violation ≡ Correctness

The Makefile adds hooks to the supported make check WHAT=... options, but the repository’s
static command reference still omits it. Developers relying on AGENTS.md therefore receive an
incomplete list of executable check phases.
Agent Prompt
## Issue description
The new `make check WHAT=hooks` phase is absent from the static command reference.

## Issue Context
`WHATS_check` now exposes `hooks`, while `AGENTS.md` presents an explicit list of supported `WHAT` values without it.

## Fix Focus Areas
- Makefile[39-39]
- AGENTS.md[143-150]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment thread scripts/lib/mcb.sh
Comment on lines +57 to +59
common_dir="$(git -C "$repo" rev-parse --path-format=absolute --git-common-dir)" \
|| mcb_die "$EX_PREREQ" "nao foi possivel resolver o diretorio Git comum de '$repo'"
printf '%s/hooks\n' "$common_dir"

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.

Action required

2. Configured hook paths ignored 🐞 Bug ≡ Correctness

mcb_git_hooks_dir always installs under <git-common-dir>/hooks, so repositories with a
non-default core.hooksPath report successful installation into a directory Git does not execute.
This silently disables the documented pre-commit enforcement for those repositories.
Agent Prompt
## Issue description
Hook installation constructs `<git-common-dir>/hooks`, ignoring repositories that configure an alternate `core.hooksPath`. Resolve the effective hooks location through Git so the installed hook is actually executed.

## Issue Context
The installer reports success after copying to the constructed directory, while project documentation describes the hook as mechanical enforcement. Extend tests to cover a configured hook path as well as primary and linked worktrees.

## Fix Focus Areas
- scripts/lib/mcb.sh[54-69]
- scripts/lib/tests/test-hooks.sh[17-35]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment thread makefiles/dispatch.mk
udeps) command -v cargo-udeps >/dev/null 2>&1 || cargo install cargo-udeps; cargo +nightly udeps --workspace ;; \
coverage) cargo tarpaulin --out Lcov --output-dir coverage --exclude-files 'crates/*/tests/integration/*' --exclude-files 'crates/*/tests/admin/*' --timeout 300 ;; \
qlty) mkdir -p docs/reports; ./scripts/analyze_qlty.py --scan --check --summary --markdown docs/reports/qlty-check-REPORTS.md; ./scripts/analyze_qlty.py --scan --smells --summary --markdown docs/reports/qlty-smells-REPORTS.md ;; \
hooks) bash scripts/lib/tests/test-hooks.sh ;; \

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.

Remediation recommended

3. Hook regression test skips ci 🐞 Bug ☼ Reliability

The new test is reachable only through WHAT=hooks; WHAT=all, which backs make ci, does not
invoke it, and the CI workflow has no separate hooks-test step. Linked-worktree hook regressions can
therefore merge without this test running.
Agent Prompt
## Issue description
The linked-worktree hook regression test is exposed as a standalone check but is absent from the canonical CI execution paths. Integrate it into `WHAT=all` or add an explicit CI step/job.

## Issue Context
`make ci` delegates to `make check WHAT=all`, whose dispatch arm excludes the hooks test. The current workflow invokes no standalone `WHAT=hooks` check.

## Fix Focus Areas
- makefiles/dispatch.mk[68-80]
- Makefile[68-68]
- .github/workflows/ci.yml[116-166]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@makefiles/dispatch.mk`:
- Around line 78-79: Update the `""|all)` branch in `makefiles/dispatch.mk` to
invoke the existing hook-validation target or command used by the `hooks)`
branch, ensuring `check WHAT=all` validates linked-worktree hook installation
while preserving the current formatting, lint, test, and MCB validation steps.

In `@scripts/lib/mcb.sh`:
- Around line 54-59: Update mcb_git_hooks_dir() to use Git’s effective hooks
directory from git rev-parse --git-path hooks instead of appending hooks to the
common directory, resolving relative paths against the repository/worktree root
as needed for worktrees. Extend the hook path coverage in
scripts/lib/tests/test-hooks.sh to verify configured relative and worktree-aware
paths; both affected sites require changes.

In `@scripts/lib/tests/test-hooks.sh`:
- Around line 5-14: Update the bootstrap Git commands in the fixture setup to
use an isolated Git configuration, including the git init and initial commit
flow. Ensure host settings such as core.hooksPath cannot affect repository
initialization or trigger unrelated hooks before install-hooks runs, while
preserving the existing fixture creation behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 49d19f7d-7fd6-47ce-84e3-c53e79d56b90

📥 Commits

Reviewing files that changed from the base of the PR and between a6d22a3 and b081ab9.

📒 Files selected for processing (5)
  • Makefile
  • makefiles/dispatch.mk
  • scripts/hooks/pre-commit
  • scripts/lib/mcb.sh
  • scripts/lib/tests/test-hooks.sh
📜 Review details
⏰ Context from checks skipped due to timeout. (4)
  • GitHub Check: Security Audit
  • GitHub Check: Validate Documentation
  • GitHub Check: Lint (Rust 2024)
  • GitHub Check: Generate Diagrams
🧰 Additional context used
📓 Path-based instructions (1)
Makefile

📄 CodeRabbit inference engine (AGENTS.md)

Makefile and makefiles/*.mk define canonical developer verbs. Trust these over ad-hoc commands.

Files:

  • Makefile
🔇 Additional comments (5)
scripts/lib/mcb.sh (1)

148-149: LGTM!

makefiles/dispatch.mk (2)

206-206: LGTM!


251-254: LGTM!

scripts/hooks/pre-commit (1)

2-3: LGTM!

Makefile (1)

39-39: LGTM!

Comment thread makefiles/dispatch.mk
Comment on lines +78 to 79
hooks) bash scripts/lib/tests/test-hooks.sh ;; \
""|all) cargo fmt --all -- --check && $(MAKE) lint-impl && $(MAKE) test && bash $(MCB_SH) validate $(if $(filter 1,$(QUICK)),quick,full) ;; \

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Include hook validation in the standard check gate.

Line 78 adds the check, but Line 79’s all branch never invokes it; therefore the CI gate (check WHAT=all) does not validate linked-worktree hook installation.

Proposed fix
-  ""|all)   cargo fmt --all -- --check && $(MAKE) lint-impl && $(MAKE) test && bash $(MCB_SH) validate $(if $(filter 1,$(QUICK)),quick,full) ;; \
+  ""|all)   cargo fmt --all -- --check && $(MAKE) lint-impl && $(MAKE) test && bash $(MCB_SH) validate $(if $(filter 1,$(QUICK)),quick,full) && $(MAKE) check WHAT=hooks ;; \

As per coding guidelines, “Makefile and makefiles/*.mk define canonical developer verbs. Trust these over ad-hoc commands.”

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
hooks) bash scripts/lib/tests/test-hooks.sh ;; \
""|all) cargo fmt --all -- --check && $(MAKE) lint-impl && $(MAKE) test && bash $(MCB_SH) validate $(if $(filter 1,$(QUICK)),quick,full) ;; \
hooks) bash scripts/lib/tests/test-hooks.sh ;; \
""|all) cargo fmt --all -- --check && $(MAKE) lint-impl && $(MAKE) test && bash $(MCB_SH) validate $(if $(filter 1,$(QUICK)),quick,full) && $(MAKE) check WHAT=hooks ;; \
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@makefiles/dispatch.mk` around lines 78 - 79, Update the `""|all)` branch in
`makefiles/dispatch.mk` to invoke the existing hook-validation target or command
used by the `hooks)` branch, ensuring `check WHAT=all` validates linked-worktree
hook installation while preserving the current formatting, lint, test, and MCB
validation steps.

Source: Coding guidelines

Comment thread scripts/lib/mcb.sh
Comment on lines +54 to +59
mcb_git_hooks_dir() {
local repo="${1:-$MCB_ROOT}"
local common_dir
common_dir="$(git -C "$repo" rev-parse --path-format=absolute --git-common-dir)" \
|| mcb_die "$EX_PREREQ" "nao foi possivel resolver o diretorio Git comum de '$repo'"
printf '%s/hooks\n' "$common_dir"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== files =="
git ls-files | rg '(^|/)mcb\.sh$|(^|/)test-hooks\.sh$|scripts/hooks/pre-commit' || true

echo "== mcb outline =="
ast-grep outline scripts/lib/mcb.sh --view expanded || true

echo "== relevant mcb snippets =="
cat -n scripts/lib/mcb.sh | sed -n '1,140p'

echo "== test-hooks snippet =="
cat -n scripts/lib/tests/test-hooks.sh | sed -n '1,90p'

echo "== searches for hooksPath or hooks-dir =="
rg -n "hooks-dir|git-hooks-dir|core\.hooksPath|hooksPath|mcb_git_hooks_dir|expected_hook|LINKED|PRIMARY" scripts || true

echo "== git version =="
git --version

Repository: marlonsc/mcb

Length of output: 12398


🏁 Script executed:

#!/bin/bash
set -euo pipefail

tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT

cd "$tmp"

echo "== default setup =="
git init -q primary
git -C primary commit --allow-empty -q -m nulo
git -C primary worktree add -q -b linked-test linked
printf 'default primary: %s\n' "$(git -C primary rev-parse --path-format=absolute --git-common-dir)/hooks"
printf 'default linked: %s\n' "$(git -C linked rev-parse --path-format=absolute --git-common-dir)"
git -C linked rev-parse --path-format=absolute --git-common-dir
git -C linked rev-parse --hook-dir | sed "s|^|$tmp/linked/|"

echo "== core.hooksPath relative setup =="
git -C primary config core.hooksPath ../custom-hooks
mkdir -p primary/custom-hooks
git -C primary commit --allow-empty -q -m nulo
printf 'custom primary rev-parse hook dir: %s\n' "$(git -C primary rev-parse --path-format=absolute --git-common-dir)"
printf 'custom primary git rev-parse --hook-dir: %s\n' "$(git -C primary rev-parse --hook-dir)"

git -C linked status --short >/dev/null
printf 'custom linked git rev-parse --hook-dir from linked: %s\n' "$(git -C linked rev-parse --hook-dir)"
printf 'custom linked path-format from linked: %s\n' "$(git -C linked rev-parse --path-format=absolute --git-common-dir)"

echo "== hook-dir vs common-dir output =="
git -C primary rev-parse --path-format=absolute --git-common-dir
git -C linked rev-parse --path-format=absolute --git-common-dir
git -C primary rev-parse --hook-dir
git -C linked rev-parse --hook-dir

echo "== Git hook-path sources / rev-parse docs excerpts =="
git rev-parse --help 2>&1 | sed -n '1,/GIT/ p' | rg -n "hook-dir|hooksPath|core\.hooksPath|--hook-dir|git dir|work tree" -C 2 || true

Repository: marlonsc/mcb

Length of output: 508


🌐 Web query:

Git documentation rev-parse --hook-dir core.hooksPath relative hook path

💡 Result:

To interact with the hooks directory in Git, you can use git rev-parse --git-path hooks, which is designed to respect the core.hooksPath configuration [1][2]. Key Technical Details: 1. Resolving the Hooks Path: The command git rev-parse --git-path hooks will output the path to the directory Git currently uses for hooks [1]. If core.hooksPath is set, this command will reflect that override [1][2]. By default, it returns a path relative to the current directory [3]. To ensure you always receive an absolute path, you can use the --path-format=absolute option: git rev-parse --path-format=absolute --git-path hooks [3]. 2. Understanding core.hooksPath: The core.hooksPath configuration allows you to point to a custom directory for hooks instead of the default $GIT_DIR/hooks [4]. When you define a relative path for core.hooksPath, it is interpreted as relative to the directory where the hooks are executed [5][4]. 3. Hook Execution Context: It is important to note that when Git runs a hook, it changes its working directory [6][7]. In a non-bare repository, it switches to the root of the working tree; in a bare repository, it switches to $GIT_DIR [6][7]. A notable exception occurs for hooks triggered during a push (such as pre-receive, update, and post-receive), which are always executed within $GIT_DIR [6][7]. Because relative core.hooksPath values are relative to the execution directory, this change of context is critical if your hook scripts rely on path-relative resources [5][4]. For managing hooks centrally, setting core.hooksPath globally is a common practice [5][4]. Alternatively, you can disable hooks entirely by setting core.hooksPath to /dev/null [4][8].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
export GIT_AUTHOR_NAME="MCB Test"
export GIT_AUTHOR_EMAIL="test@example.com"
export GIT_COMMITTER_NAME="MCB Test"
export GIT_COMMITTER_EMAIL="test@example.com"

cd "$tmp"

echo "== default setup =="
git init -q primary
git -C primary commit --allow-empty -q -m nulo
git -C primary worktree add -q -b linked-test linked
printf 'default primary hook dir: "%s"\n' "$(git -C primary rev-parse --path-format=absolute --git-path hooks)"
printf 'default linked hook dir: "%s"\n' "$(git -C linked rev-parse --path-format=absolute --git-path hooks)"

echo "== core.hooksPath relative setup =="
git -C primary config core.hooksPath ../custom-hooks
rm -rf primary/custom-hooks
mkdir -p primary/custom-hooks
git -C primary commit --allow-empty -q -m nulo
printf 'custom primary git-path hooks: "%s"\n' "$(git -C primary rev-parse --path-format=absolute --git-path hooks)"
printf 'custom linked git-path hooks: "%s"\n' "$(git -C linked rev-parse --path-format=absolute --git-path hooks)"

echo "== actual hook execution directory =="
printf 'custom primary actual hook dir: "%s"\n' "$(git -C primary rev-parse --path-format=absolute --hook-dir)"
printf 'custom linked actual hook dir: "%s"\n' "$(git -C linked rev-parse --path-format=absolute --hook-dir)"

echo "== current common-dir-based hook dir from code =="
common_primary="$(git -C primary rev-parse --path-format=absolute --git-common-dir)"
common_linked="$(git -C linked rev-parse --path-format=absolute --git-common-dir)"
printf 'primary common: "%s"\n' "$common_primary/hooks"
printf 'linked common: "%s"\n' "$common_linked/hooks"
printf 'primary linked common: "%s"\n' "$common_linked/hooks"

Repository: marlonsc/mcb

Length of output: 811


🏁 Script executed:

#!/bin/bash
set -euo pipefail

tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
export GIT_AUTHOR_NAME="MCB Test"
export GIT_AUTHOR_EMAIL="test@example.com"
export GIT_COMMITTER_NAME="MCB Test"
export GIT_COMMITTER_EMAIL="test@example.com"

cd "$tmp"

echo "== repository setup =="
git init -q primary
git -C primary commit --allow-empty -q -m nulo
git -C primary worktree add -q -b linked-test linked

echo "== core.hooksPath custom hooks setup =="
git -C primary config core.hooksPath ../custom-hooks
mkdir -p primary/custom-hooks
git -C primary commit --allow-empty -q -m nulo

echo "== Git path helpers for primary/worktree =="
printf 'primary --git-path hooks from primary: "%s"\n' "$(git -C primary rev-parse --path-format=absolute --git-path hooks)"
printf 'linked --git-path hooks from linked: "%s"\n' "$(git -C linked rev-parse --path-format=absolute --git-path hooks)"

echo "== current common-dir-based hook dir from code =="
common_primary="$(git -C primary rev-parse --path-format=absolute --git-common-dir)"
printf 'primary common: "%s"/hooks\n' "$common_primary"
common_linked="$(git -C linked rev-parse --path-format=absolute --git-common-dir)"
printf 'linked common: "%s"/hooks\n' "$common_linked"

echo "== hook dir option support =="
git rev-parse --help | sed -n '/git rev-parse/,/GIT/ p' | rg -- '--hook-dir|hooksPath|core\.hooksPath|--git-path' -C 2 || true
printf 'primary hook-dir from primary: "%s"\n' "$(git -C primary rev-parse --path-format=absolute --hook-dir)"
printf 'linked hook-dir from linked: "%s"\n' "$(git -C linked rev-parse --path-format=absolute --hook-dir)"

Repository: marlonsc/mcb

Length of output: 602


Honor Git’s configured hooks path when installing hooks.

mcb_git_hooks_dir() currently writes to $git-common-dir/hooks, but when a repo sets core.hooksPath, Git uses its configured hook directory instead. Use the repository’s effective hook directory via git rev-parse --git-path hooks (and resolve relative values from the worktree root, accounting for worktrees) so installs don’t land where commits will not execute hooks.

📍 Affects 2 files
  • scripts/lib/mcb.sh#L54-L59 (this comment)
  • scripts/lib/tests/test-hooks.sh#L17-L35
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/lib/mcb.sh` around lines 54 - 59, Update mcb_git_hooks_dir() to use
Git’s effective hooks directory from git rev-parse --git-path hooks instead of
appending hooks to the common directory, resolving relative paths against the
repository/worktree root as needed for worktrees. Extend the hook path coverage
in scripts/lib/tests/test-hooks.sh to verify configured relative and
worktree-aware paths; both affected sites require changes.

Comment on lines +5 to +14
FIXTURE="$(mktemp -d)"
trap 'rm -rf "$FIXTURE"' EXIT

PRIMARY="$FIXTURE/primary"
LINKED="$FIXTURE/linked"

git init -q "$PRIMARY"
git -C "$PRIMARY" config user.email test@example.com
git -C "$PRIMARY" config user.name "MCB Test"
git -C "$PRIMARY" commit --allow-empty -q -m initial

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== file excerpt =="
sed -n '1,80p' scripts/lib/tests/test-hooks.sh 2>/dev/null || true

echo
echo "== related hook/config references =="
rg -n "hooksPath|XDG|HOME|git init|git -C|hook|hook directory" scripts/lib/mcb.sh scripts/lib/tests/test-hooks.sh scripts 2>/dev/null | head -200

echo
echo "== git version =="
git --version 2>/dev/null || true

echo
echo "== inspect mcb hook installer snippets if present =="
fd -a 'mcb\.sh|test-hooks\.sh' scripts lib 2>/dev/null | sed 's#^\./##'
for f in scripts/lib/mcb.sh scripts/lib/tests/test-hooks.sh; do
  if [ -f "$f" ]; then
    echo "--- $f"
    wc -l "$f"
  fi
done

Repository: marlonsc/mcb

Length of output: 8156


🌐 Web query:

Git hook lookup core.hooksPath documentation

💡 Result:

In Git, the core.hooksPath configuration variable allows you to specify a custom directory for Git hooks, overriding the default location [1][2][3]. How it works: By default, Git searches for hooks in the $GIT_DIR/hooks directory (typically.git/hooks in a local repository) [1][3]. When you set core.hooksPath, Git instead looks for hook scripts within the directory you have specified [1][2]. For example, if you set this to /etc/git/hooks, Git will attempt to execute /etc/git/hooks/pre-receive when the pre-receive event is triggered, rather than looking in $GIT_DIR/hooks/pre-receive [1]. Key Details: - Path Flexibility: The path can be provided as either an absolute or relative path [1][2]. If a relative path is used, it is interpreted as relative to the directory where the hooks are executed [1][2]. - Disabling Hooks: Setting core.hooksPath to /dev/null effectively disables all hooks [2]. This can be useful on a per-command basis, for example: git -c core.hooksPath=/dev/null commit [2]. - Use Case: This configuration is primarily used to manage hooks centrally across multiple repositories, rather than maintaining individual hook scripts inside each repository's.git/hooks directory [1][2]. Note on Newer Git Versions: While core.hooksPath is the traditional method for defining hook directories, newer versions of Git have introduced a more flexible hook configuration system (accessible via git config hook..*), which allows you to define multiple commands for a single hook event and control their execution order [4]. Traditional hooks (those found in the directory specified by core.hooksPath) are executed after any hooks configured via this newer system [4].

Citations:


Isolate the fixture from host Git configuration.

The bootstrap git commit runs in the current developer/runner environment, so host configuration such as core.hooksPath can change hook lookup or execute unrelated hooks before install-hooks writes the expected fixtures. Use a temporary clean Git config, such as git -c core.hooksPath=/dev/null ... or an isolated XDG_CONFIG_HOME, for the bootstrap initialization and commit.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@scripts/lib/tests/test-hooks.sh` around lines 5 - 14, Update the bootstrap
Git commands in the fixture setup to use an isolated Git configuration,
including the git init and initial commit flow. Ensure host settings such as
core.hooksPath cannot affect repository initialization or trigger unrelated
hooks before install-hooks runs, while preserving the existing fixture creation
behavior.

Comment thread makefiles/dispatch.mk
show) git show --stat $(or $(REF),HEAD) ;; \
add) bash $(MCB_SH) files-safe "$(FILES)"; $(call require_var,FILES); git add $(FILES) ;; \
commit) $(call require_var,MSG); bash $(MCB_SH) files-safe "$(FILES)"; [ -n "$(FILES)" ] && git add $(FILES) || true; $(call gate,commit); git commit -m "$(MSG)" ;; \
commit) $(call require_var,MSG); bash $(MCB_SH) files-safe "$(FILES)"; $(call gate,commit); [ -n "$(FILES)" ] && git add $(FILES) || true; git commit -m "$(MSG)" ;; \

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.

Action required

1. git add errors swallowed 📘 Rule violation ☼ Reliability

The && git add $(FILES) || true chain converts a failed git add into success, allowing `git
commit` to proceed with incomplete or unintended staged content. This silently hides a fallible
operation in the modified commit path.
Agent Prompt
## Issue description
The commit dispatch silently ignores `git add` failures because `|| true` applies to the complete `test && git add` chain.

## Issue Context
An empty `FILES` value should remain valid, but a non-empty value whose `git add` fails must stop the command before `git commit` executes. Use an explicit conditional so only the empty-value case is skipped.

## Fix Focus Areas
- makefiles/dispatch.mk[206-206]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment thread makefiles/dispatch.mk
define DISPATCH_SETUP
@case "$(WHAT)" in \
hooks) cp scripts/hooks/pre-commit .git/hooks/pre-commit; chmod +x .git/hooks/pre-commit; echo "✓ pre-commit hook installed" ;; \
hooks) bash $(MCB_SH) install-hooks ;; \

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.

Remediation recommended

2. Documented install breaks worktrees 🐞 Bug ≡ Correctness

The new worktree-safe installer is used by make setup, but the operational guide still instructs
users to copy into .git/hooks. Because .git is a file in linked worktrees, users following those
instructions cannot install the pre-commit hook there.
Agent Prompt
## Issue description
The operational guide still installs the pre-commit hook by copying into `.git/hooks`. That path is invalid in linked worktrees, where `.git` is a file; update both documented installation examples to invoke the new worktree-aware installer, preferably `make setup WHAT=hooks`.

## Issue Context
The setup dispatch now delegates to `mcb.sh install-hooks`, which resolves the shared Git hooks directory. The linked-worktree test confirms that `.git` is a file in that environment.

## Fix Focus Areas
- docs/operations/CI_RELEASE.md[52-60]
- docs/operations/CI_RELEASE.md[654-660]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@qodo-code-review

Copy link
Copy Markdown
Contributor

Code review by qodo was updated up to the latest commit b081ab9

@cubic-dev-ai cubic-dev-ai Bot 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.

4 issues found across 5 files

Confidence score: 2/5

  • In scripts/lib/mcb.sh, hook-path resolution/install failures can still return success, so callers may proceed as if setup worked and, in permissive environments, a bad path can lead to copying the hook to /pre-commit — make the install path resolution fail-closed and propagate non-zero exit codes.
  • In scripts/lib/mcb.sh, repos using core.hooksPath can report a successful install while Git runs hooks from a different location, so the pre-commit check is silently bypassed — resolve and target the effective hooks directory via git rev-parse --git-path hooks.
  • In scripts/lib/mcb.sh, make setup WHAT=hooks currently replaces any existing pre-commit hook, which can remove user/project automation and regress local safeguards — preserve/chain the prior hook, archive it, or require explicit overwrite confirmation.
  • In makefiles/dispatch.mk, the linked-worktree regression test is not covered by default checks/CI paths, so this behavior can regress unnoticed after merge — include the hooks test path in check WHAT=all/standard test gates.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="makefiles/dispatch.mk">

<violation number="1" location="makefiles/dispatch.mk:78">
P2: The linked-worktree regression test is not exercised by any existing default or CI gate. The new `hooks` case is only reachable via an explicit `make check WHAT=hooks`; `check WHAT=all`, `make test`, and the commands in `.github/workflows/ci.yml` never select it. Wiring this phase into an automated CI/default gate would ensure the worktree installation behavior cannot regress unnoticed.</violation>
</file>

<file name="scripts/lib/mcb.sh">

<violation number="1" location="scripts/lib/mcb.sh:56">
P1: Repositories with `core.hooksPath` configured will report a successful installation, but Git will execute hooks from the configured path and skip this pre-commit hook. Resolve the effective path with `git rev-parse --git-path hooks`, which also preserves linked-worktree handling.</violation>

<violation number="2" location="scripts/lib/mcb.sh:65">
P1: Library callers can receive success after hook-path resolution or installation fails; with sufficient permissions, an invalid repo can even copy the hook to `/pre-commit` because the failed command substitution leaves `hooks_dir` empty. Propagate each command failure explicitly instead of relying on the dispatcher's `set -e`.</violation>

<violation number="3" location="scripts/lib/mcb.sh:67">
P2: Running `make setup WHAT=hooks` destroys any existing pre-commit hook, potentially removing unrelated project checks or user automation. Preserve/chain the existing hook, archive it, or refuse replacement unless it is already the managed MCB hook.</violation>
</file>

Shadow auto-approve: would not auto-approve because issues were found.

Fix all with cubic | Re-trigger cubic

Comment thread scripts/lib/mcb.sh
Comment on lines +56 to +59
local common_dir
common_dir="$(git -C "$repo" rev-parse --path-format=absolute --git-common-dir)" \
|| mcb_die "$EX_PREREQ" "nao foi possivel resolver o diretorio Git comum de '$repo'"
printf '%s/hooks\n' "$common_dir"

@cubic-dev-ai cubic-dev-ai Bot Jul 29, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1: Repositories with core.hooksPath configured will report a successful installation, but Git will execute hooks from the configured path and skip this pre-commit hook. Resolve the effective path with git rev-parse --git-path hooks, which also preserves linked-worktree handling.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At scripts/lib/mcb.sh, line 56:

<comment>Repositories with `core.hooksPath` configured will report a successful installation, but Git will execute hooks from the configured path and skip this pre-commit hook. Resolve the effective path with `git rev-parse --git-path hooks`, which also preserves linked-worktree handling.</comment>

<file context>
@@ -51,6 +51,24 @@ mcb_retry() { local n="$1" s="$2"; shift 2; local t=1; while ! "$@"; do [ "$t" -
 
+mcb_git_hooks_dir() {
+  local repo="${1:-$MCB_ROOT}"
+  local common_dir
+  common_dir="$(git -C "$repo" rev-parse --path-format=absolute --git-common-dir)" \
+    || mcb_die "$EX_PREREQ" "nao foi possivel resolver o diretorio Git comum de '$repo'"
</file context>
Suggested change
local common_dir
common_dir="$(git -C "$repo" rev-parse --path-format=absolute --git-common-dir)" \
|| mcb_die "$EX_PREREQ" "nao foi possivel resolver o diretorio Git comum de '$repo'"
printf '%s/hooks\n' "$common_dir"
local hooks_dir
hooks_dir="$(git -C "$repo" rev-parse --path-format=absolute --git-path hooks)" \
|| mcb_die "$EX_PREREQ" "nao foi possivel resolver o diretorio de hooks Git de '$repo'"
printf '%s\n' "$hooks_dir"
Fix with cubic

Comment thread scripts/lib/mcb.sh
Comment on lines +65 to +69
hooks_dir="$(mcb_git_hooks_dir "$repo")"
mkdir -p "$hooks_dir"
cp "$MCB_ROOT/scripts/hooks/pre-commit" "$hooks_dir/pre-commit"
chmod +x "$hooks_dir/pre-commit"
mcb_ok "pre-commit hook installed at $hooks_dir/pre-commit"

@cubic-dev-ai cubic-dev-ai Bot Jul 29, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1: Library callers can receive success after hook-path resolution or installation fails; with sufficient permissions, an invalid repo can even copy the hook to /pre-commit because the failed command substitution leaves hooks_dir empty. Propagate each command failure explicitly instead of relying on the dispatcher's set -e.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At scripts/lib/mcb.sh, line 65:

<comment>Library callers can receive success after hook-path resolution or installation fails; with sufficient permissions, an invalid repo can even copy the hook to `/pre-commit` because the failed command substitution leaves `hooks_dir` empty. Propagate each command failure explicitly instead of relying on the dispatcher's `set -e`.</comment>

<file context>
@@ -51,6 +51,24 @@ mcb_retry() { local n="$1" s="$2"; shift 2; local t=1; while ! "$@"; do [ "$t" -
+mcb_install_hooks() {
+  local repo="${1:-$MCB_ROOT}"
+  local hooks_dir
+  hooks_dir="$(mcb_git_hooks_dir "$repo")"
+  mkdir -p "$hooks_dir"
+  cp "$MCB_ROOT/scripts/hooks/pre-commit" "$hooks_dir/pre-commit"
</file context>
Suggested change
hooks_dir="$(mcb_git_hooks_dir "$repo")"
mkdir -p "$hooks_dir"
cp "$MCB_ROOT/scripts/hooks/pre-commit" "$hooks_dir/pre-commit"
chmod +x "$hooks_dir/pre-commit"
mcb_ok "pre-commit hook installed at $hooks_dir/pre-commit"
hooks_dir="$(mcb_git_hooks_dir "$repo")" || return $?
mkdir -p "$hooks_dir" || return $?
cp "$MCB_ROOT/scripts/hooks/pre-commit" "$hooks_dir/pre-commit" || return $?
chmod +x "$hooks_dir/pre-commit" || return $?
mcb_ok "pre-commit hook installed at $hooks_dir/pre-commit"
Fix with cubic

Comment thread makefiles/dispatch.mk
udeps) command -v cargo-udeps >/dev/null 2>&1 || cargo install cargo-udeps; cargo +nightly udeps --workspace ;; \
coverage) cargo tarpaulin --out Lcov --output-dir coverage --exclude-files 'crates/*/tests/integration/*' --exclude-files 'crates/*/tests/admin/*' --timeout 300 ;; \
qlty) mkdir -p docs/reports; ./scripts/analyze_qlty.py --scan --check --summary --markdown docs/reports/qlty-check-REPORTS.md; ./scripts/analyze_qlty.py --scan --smells --summary --markdown docs/reports/qlty-smells-REPORTS.md ;; \
hooks) bash scripts/lib/tests/test-hooks.sh ;; \

@cubic-dev-ai cubic-dev-ai Bot Jul 29, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: The linked-worktree regression test is not exercised by any existing default or CI gate. The new hooks case is only reachable via an explicit make check WHAT=hooks; check WHAT=all, make test, and the commands in .github/workflows/ci.yml never select it. Wiring this phase into an automated CI/default gate would ensure the worktree installation behavior cannot regress unnoticed.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At makefiles/dispatch.mk, line 78:

<comment>The linked-worktree regression test is not exercised by any existing default or CI gate. The new `hooks` case is only reachable via an explicit `make check WHAT=hooks`; `check WHAT=all`, `make test`, and the commands in `.github/workflows/ci.yml` never select it. Wiring this phase into an automated CI/default gate would ensure the worktree installation behavior cannot regress unnoticed.</comment>

<file context>
@@ -75,6 +75,7 @@ define DISPATCH_CHECK
   udeps)    command -v cargo-udeps >/dev/null 2>&1 || cargo install cargo-udeps; cargo +nightly udeps --workspace ;; \
   coverage) cargo tarpaulin --out Lcov --output-dir coverage --exclude-files 'crates/*/tests/integration/*' --exclude-files 'crates/*/tests/admin/*' --timeout 300 ;; \
   qlty)     mkdir -p docs/reports; ./scripts/analyze_qlty.py --scan --check --summary --markdown docs/reports/qlty-check-REPORTS.md; ./scripts/analyze_qlty.py --scan --smells --summary --markdown docs/reports/qlty-smells-REPORTS.md ;; \
+  hooks)    bash scripts/lib/tests/test-hooks.sh ;; \
   ""|all)   cargo fmt --all -- --check && $(MAKE) lint-impl && $(MAKE) test && bash $(MCB_SH) validate $(if $(filter 1,$(QUICK)),quick,full) ;; \
   *)        printf "ERRO: WHAT '%s' invalido. Validos: $(WHATS_check)\n" "$(WHAT)" >&2; exit 2 ;; \
</file context>
Fix with cubic

Comment thread scripts/lib/mcb.sh
local hooks_dir
hooks_dir="$(mcb_git_hooks_dir "$repo")"
mkdir -p "$hooks_dir"
cp "$MCB_ROOT/scripts/hooks/pre-commit" "$hooks_dir/pre-commit"

@cubic-dev-ai cubic-dev-ai Bot Jul 29, 2026

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: Running make setup WHAT=hooks destroys any existing pre-commit hook, potentially removing unrelated project checks or user automation. Preserve/chain the existing hook, archive it, or refuse replacement unless it is already the managed MCB hook.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At scripts/lib/mcb.sh, line 67:

<comment>Running `make setup WHAT=hooks` destroys any existing pre-commit hook, potentially removing unrelated project checks or user automation. Preserve/chain the existing hook, archive it, or refuse replacement unless it is already the managed MCB hook.</comment>

<file context>
@@ -51,6 +51,24 @@ mcb_retry() { local n="$1" s="$2"; shift 2; local t=1; while ! "$@"; do [ "$t" -
+  local hooks_dir
+  hooks_dir="$(mcb_git_hooks_dir "$repo")"
+  mkdir -p "$hooks_dir"
+  cp "$MCB_ROOT/scripts/hooks/pre-commit" "$hooks_dir/pre-commit"
+  chmod +x "$hooks_dir/pre-commit"
+  mcb_ok "pre-commit hook installed at $hooks_dir/pre-commit"
</file context>
Fix with cubic

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 5 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Shadow auto-approve: would auto-approve. Fixes hooks installation in linked git worktrees and adds a test to pin the behavior. All changes are in development tooling (shell scripts, Makefile) with no production or operational impact.

Re-trigger cubic

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