Skip to content

cwd: git_root misses a worktree or submodule (.git file) when git cannot run #586

Open

Description

@ThomasK33

cwd.git_root misses a git worktree or a submodule when git cannot run.

Defect. When git is missing from PATH or fails, the fallback walk in lua/claudecode/cwd.lua tests vim.fn.isdirectory(dir .. "/.git"). A worktree or a submodule has a .git file (gitdir: ...), so the walk skips it and returns nil, or a repository above it. With git, the answer is the worktree folder.

Reproduction (on main, Neovim 0.12.3 and 0.8.0):

git init main && git -C main commit --allow-empty -m i
git -C main worktree add ../wt && mkdir wt/sub

Run require("claudecode.cwd").git_root("<R>/wt") and git_root("<R>/wt/sub") once with git on PATH and once with PATH set to an empty folder (vim.o.shell = "/bin/sh"). With git: <R>/wt for both. Without git: nil for both.

Fix. In the walk, also accept vim.fn.filereadable(dir .. "/.git") == 1. Say "a .git folder or file" in lua/claudecode/README.md. Add worktree and submodule cases to the no-git mode of tests/integration/cwd_path_characters_spec.lua (create them with real git, look them up with git off PATH). cwd.lua is covered by verify-diff-lifecycle, so run the full check.sh and --record.

Test cleanup in the same PR (tests/unit/cwd_spec.lua):

  1. Lines 46 and 57 use assert(os.execute("mkdir -p ...")). That never fails under LuaJIT, because os.execute returns 0 or 256 and both are truthy (test: fail the test when a shell setup command exits with a non-zero status #570 fixed the same bug in two other files). Check status == 0 or status == true, and move test: fail the test when a shell setup command exits with a non-zero status #570's local shell helper to tests/helpers/.
  2. saved.finddir is saved (line 25) and restored (line 30), but nothing stubs finddir since fix(cwd): find a repository whose folder name has a space, a comma or other path characters #561. Delete both uses.

Related: the symlink walk issue filed next to this one touches the same walk; do both in one PR or this one first.

Owner: the next maintainer pass on cwd.lua. Deferred from the README verification run with the maintainer's agreement.


Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high

Activity

  1. ThomasK33 commented on Nov 13, 2026

    @ThomasK33
    MemberAuthor

    Added with the maintainer's agreement (same shell() helper move as above): four more setup commands in tests/lockfile_test.lua do not check their result.

    Route them through the shared shell() helper, and show each one red with a forced failure (false && <command>) and green normally.


    Generated with xum • Model: anthropic:claude-opus-5-5 • Thinking: high

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triageAwaiting maintainer triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions