Skip to content

fix(codegen): handle git worktrees correctly when detecting git roots#5302

Open
thehowl wants to merge 2 commits intognolang:masterfrom
thehowl:claude/fix-git-worktree-detection-kV29h
Open

fix(codegen): handle git worktrees correctly when detecting git roots#5302
thehowl wants to merge 2 commits intognolang:masterfrom
thehowl:claude/fix-git-worktree-detection-kV29h

Conversation

@thehowl
Copy link
Member

@thehowl thehowl commented Mar 16, 2026

Updated git root detection logic in two locations to properly handle git worktrees by using git rev-parse --show-toplevel as the primary method, with a fallback to the existing directory walking approach.

Key Changes

  • misc/genstd/util.go: Modified findDirs() to first attempt git rev-parse --show-toplevel before falling back to walking up parent directories looking for .git
    • Properly calculates relative path based on the git root returned by the command
    • Normalizes path separators to forward slashes for consistency
  • gnovm/pkg/gnolang/internal/softfloat/gen/main.go: Modified gitRoot() to use the same git rev-parse --show-toplevel approach with fallback to the original directory walking logic

Implementation Details

  • git rev-parse --show-toplevel correctly resolves the actual git repository root even when working in a git worktree, whereas walking up directories from the current working directory may not
  • Both implementations maintain backward compatibility by falling back to the original directory-walking approach if the git command fails
  • The fallback ensures the code continues to work in environments where git may not be available or in non-git directories

This was an attempt to using claude code on web; but while good it seems to me it does too much of a self-promotion on itself (placing the session link in all of the commits). Still, the change is good and will help anyone who wants to use these in worktrees, considering also that they're becoming more ubiquitous with coding agents.

thehowl added 2 commits March 16, 2026 14:19
Use `git rev-parse --show-toplevel` as the primary mechanism for
finding the git root directory, falling back to the existing
parent-directory walk when the git command is unavailable. The
command-based approach correctly handles git worktrees, where the
`.git` entry is a file (not a directory) pointing to the worktree
metadata rather than the repo root.

https://claude.ai/code/session_011dNYdysBmW5maTxqEVdxiz
@Gno2D2
Copy link
Collaborator

Gno2D2 commented Mar 16, 2026

🛠 PR Checks Summary

All Automated Checks passed. ✅

Manual Checks (for Reviewers):
  • IGNORE the bot requirements for this PR (force green CI check)
Read More

🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers.

✅ Automated Checks (for Contributors):

🟢 Maintainers must be able to edit this pull request (more info)

☑️ Contributor Actions:
  1. Fix any issues flagged by automated checks.
  2. Follow the Contributor Checklist to ensure your PR is ready for review.
    • Add new tests, or document why they are unnecessary.
    • Provide clear examples/screenshots, if necessary.
    • Update documentation, if required.
    • Ensure no breaking changes, or include BREAKING CHANGE notes.
    • Link related issues/PRs, where applicable.
☑️ Reviewer Actions:
  1. Complete manual checks for the PR, including the guidelines and additional checks if applicable.
📚 Resources:
Debug
Automated Checks
Maintainers must be able to edit this pull request (more info)

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 The pull request was created from a fork (head branch repo: thehowl/gno)

Then

🟢 Requirement satisfied
└── 🟢 Maintainer can modify this pull request

Manual Checks
**IGNORE** the bot requirements for this PR (force green CI check)

If

🟢 Condition met
└── 🟢 On every pull request

Can be checked by

  • Any user with comment edit permission

@codecov
Copy link

codecov bot commented Mar 16, 2026

Codecov Report

❌ Patch coverage is 85.71429% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
misc/genstd/util.go 85.71% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📦 🤖 gnovm Issues or PRs gnovm related

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants