Skip to content

fix(trunk): anchor git-diff-check at the workspace root - #198

Merged
ss-o merged 1 commit into
mainfrom
fix/trunk-git-diff-check-submodule-gitdir
Aug 29, 2026
Merged

fix(trunk): anchor git-diff-check at the workspace root#198
ss-o merged 1 commit into
mainfrom
fix/trunk-git-diff-check-submodule-gitdir

Conversation

@ss-o

@ss-o ss-o commented Aug 29, 2026

Copy link
Copy Markdown
Member

Summary

git-diff-check failed on every run in this repository with:

fatal: not a git repository: (null)

Trunk copies lint targets into a sandbox directory (/tmp/trunk-<uid>/…) and runs the linter from there. This repository is consumed as a submodule of the Z-Shell meta-workspace, so its .git is a file containing a gitdir path relative to the superproject:

gitdir: ../../../.git/modules/…

That relative path does not resolve from the sandbox, so git diff --check could not find a repository and exited 128 on every target.

Fix

Anchor the command at the real workspace so repository discovery resolves against the actual checkout:

lint:
  definitions:
    - name: git-diff-check
      commands:
        - name: lint
          run: git -C "${workspace}" diff --check ${target}

This is the override documented for relative-gitdir checkouts; the upstream plugin definition is otherwise unchanged.

Scope

The same failure affected 9 repositories in the workspace. Sibling PRs carry the identical change. z-shell/zsh-lint was checked and deliberately not patched — its gitdir is absolute, so it was never affected.

Test plan

  • trunk check --no-fix --ci --filter=git-diff-check <file> returns ✔ No issues (previously exit 128)
  • trunk check --no-fix --ci <file> reports no not a git repository errors and no missing binaries
  • trunk.yaml parses with exactly one lint.definitions key and one git-diff-check entry (guards against a duplicate-key merge that would silently drop other custom linter definitions)

Note for reviewers

CI runners clone normally, so .git is a real directory there and this check was already passing in CI. The bug only reproduces in a submodule/worktree checkout — which is how the meta-workspace consumes this repo. The override is a no-op for the CI case.

git-diff-check invoked `git diff --check ${target}` from Trunk's
sandbox copy of the target. This repository is consumed as a submodule, so
its `.git` is a file whose gitdir is relative to the superproject. The
sandbox copy invalidates that relative path and every run failed with:

    fatal: not a git repository: (null)

Anchor the command at ${workspace} so repository discovery resolves against
the real checkout instead of the sandbox directory.

Verified: `trunk check --no-fix --ci --filter=git-diff-check` reports
"No issues" where it previously exited 128.
@ss-o
ss-o merged commit b7cf1ca into main Aug 29, 2026
8 checks passed
@ss-o
ss-o deleted the fix/trunk-git-diff-check-submodule-gitdir branch August 29, 2026 02:19
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