Skip to content

Status.getUntrackedFolders() silently drops untracked folders after an unrelated staged deletion #279

Description

@lucian-cm

Version

org.eclipse.jgit:org.eclipse.jgit:6.10.1.202505221210-r

Operating System

Windows

Bug description

Environment

  • JGit version: org.eclipse.jgit:org.eclipse.jgit:6.10.1.202505221210-r
  • Java: Azul Zulu 17.60+17 (Java 17)
  • OS: Windows 11
    Note: OS and Java version are listed for completeness but are most likely irrelevant.

Summary

Status.getUntrackedFolders() can silently omit untracked folders that are
still present and untracked on disk, as soon as any other, unrelated
tracked file elsewhere in the repository is deleted (e.g. via git rm)
without being committed.

Steps to reproduce

  1. Create a repo with:

    a/
      first.txt
    b/
      second.txt
    

    Commit both files (git add -A && git commit -m init).

  2. Run the following against the repo and observe the (correct) output:

    File file = Path.of("path/to/.git").toFile();
    try (Repository repository = new FileRepositoryBuilder()
            .setMustExist(true)
            .setGitDir(file)
            .build();
         Git git = Git.wrap(repository)) {
        Status status = git.status().call();
        System.out.println("Untracked folders: " + status.getUntrackedFolders());
    }

    Output: Untracked folders: [] — correct, nothing untracked yet.

  3. Create an empty untracked folder: mkdir a/untracked. Run the same code.

    Output: Untracked folders: [a/untracked] — correct.

  4. Now, without touching a/ at all, remove an unrelated tracked file in a
    different directory: git rm b/second.txt (staged deletion, not yet
    committed). Run the same code again.

    Actual output: Untracked folders: []

    Expected output: Untracked folders: [a/untracked]

a/untracked is still sitting on disk, untouched, still untracked — but
it disappears from the result purely because an unrelated file was
staged for deletion elsewhere in the repo.

A minimal reproducer project (zip with the a//b/ layout is attached.

scenario.zip

Impact

Any consumer relying on Status.getUntrackedFolders() can get incomplete results:
an untracked folder that is correctly reported in isolation can silently
disappear from the result once an unrelated staged deletion exists
elsewhere in the repository, even though the folder itself was never
touched. This is a correctness bug for any tool building a git status-equivalent view on top of JGit.

Actual behavior

Expected behavior

Relevant log output

Other information

No response

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