Skip to content

[Maintainability] Dead submodule-detection branch in getUntrackedDiff never executes #275

Description

@404-Page-Found

Description

getUntrackedDiff filters untracked entries to detect directories that are git repos (submodules) by checking entry.endsWith('/') and running git rev-parse --verify HEAD per entry. But git ls-files --others -z (called at line 146) emits individual file paths — without --directory it never outputs a directory with a trailing slash — so the endsWith('/') branch is unreachable. The entire pathspecs filter and its per-entry execFileSync calls are dead code that runs for every unstaged-diff computation.

Note the filter also resolves cwd: resolve(entry) against the process CWD rather than the repo root, which would misbehave if the branch were ever reachable from a subdirectory.

Location

src/git/diff.ts lines 156–171

Code

const pathspecs = untrackedEntries.filter((entry) => {
  if (!entry.endsWith('/')) {  // never true for `ls-files --others` output
    return true;
  }
  try {
    execFileSync(getGitExecutable(), ['rev-parse', '--verify', 'HEAD'], {
      cwd: resolve(entry),  // also resolves against process CWD, not repo root
      ...

Suggested fix

Remove the submodule branch entirely (files-only output needs no filtering), or if submodule-aware behavior is intended, detect submodules properly via git submodule foreach --quiet / --others --directory and resolve paths against the repo root.

Impact

Dead code that gives a false impression of submodule handling; every unstaged-diff computation pays for filtering and potential per-entry git spawns for nothing.

Activity

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

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions