Skip to content

Worktree.Status() descends into nested git worktree directories, reporting false untracked files #1896

@jallum

Description

@jallum

Description

Worktree.Status() reports files as untracked (??) inside directories that are git worktrees (i.e., directories containing a .git file pointing to another gitdir). Real git status recognizes these .git files as worktree boundaries and does not descend into them.

Steps to reproduce

# Create a repo with a committed file
mkdir /tmp/test-repo && cd /tmp/test-repo
git init && echo "hello" > file.txt && git add . && git commit -m "init"

# Create a worktree in a subdirectory
git worktree add .worktrees/feature feature --no-track -b feature

# Real git: clean
git status --porcelain
# (no output)

# go-git: reports files inside the worktree as untracked
repo, _ := git.PlainOpen("/tmp/test-repo")
wt, _ := repo.Worktree()
st, _ := wt.Status()
fmt.Println(st.IsClean()) // false — should be true
for path, s := range st {
    fmt.Printf("%c%c %s\n", s.Staging, s.Worktree, path)
}
// Prints:
// ?? .worktrees/feature/file.txt

Expected behavior

Worktree.Status() should recognize directories containing a .git file as worktree (or submodule) boundaries and skip them during filesystem traversal, matching the behavior of git status.

Actual behavior

The filesystem walker descends into worktree directories and reports their contents as untracked files in the parent repository.

Environment

  • go-git v5.16.5
  • Go 1.24
  • macOS / Darwin 25.2.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions