Skip to content

[package-deps-hash] Skip untracked nested Git repositories when computing repo state - #6239

Open
Ian Clanton-Thuon (iclanton) wants to merge 3 commits into
microsoft:mainfrom
iclanton:package-deps-hash-nested-repo
Open

Ian Clanton-Thuon (iclanton) wants to merge 3 commits into
microsoft:mainfrom
iclanton:package-deps-hash-nested-repo

Conversation

@iclanton

Copy link
Copy Markdown
Member

Summary

When a checkout removes a submodule but its folder isn't empty, Git warns unable to rmdir '<path>': Directory not empty and leaves the folder on disk as an untracked nested Git repository. Rush then fails to compute the repo state with:

Error calculating the state of the repo. (inner error: Error: git hash-object exited with code 128:
fatal: Unable to hash server/SonyAudioControlApi/

and, with the build cache enabled, fails with Build cache is only supported if running in a Git repository.

This was hit in CI on a persistent agent right after merging a PR that removed a submodule. It isn't specific to shallow clones; it reproduces with full history.

Details

git status -u lists every file in untracked folders, but it doesn't look inside an untracked nested Git repository (a folder with a .git in it). It reports that folder once, with a trailing /. classifyLocallyModifiedFiles passed that path to git hash-object, which can't hash a folder, so the whole calculation failed.

The fix skips workingTree entries that end in /. They are neither hashed nor removed, and hasUncommittedChanges is still true. Ordinary untracked files in untracked folders are unaffected, because -u lists them individually. RepoStateCache uses the same classifier, and it runs git status with status.showUntrackedFiles=all, so it gets the same fix.

The contents of an untracked nested repository were never included in the state before (Git doesn't list them), so this doesn't change any hashes; it only stops the failure.

How it was tested

Added two tests in UnhashablePaths.test.ts, which check both getDetailedRepoStateAsync and RepoStateCache:

  • A submodule is added, then removed in a later commit; checking out the removal leaves the submodule folder on disk.
  • An untracked nested clone sits next to an ordinary untracked file, which is still hashed.

Both tests failed with Unable to hash ... before the fix. The getRepoState, UnhashablePaths and RepoStateCache suites pass (96 tests), along with the build, lint and API Extractor.

…ting repo state

A submodule removed by a checkout can be left on disk when its folder is
not empty. `git status -u` doesn't descend into untracked nested Git
repositories and reports them as folders with a trailing slash, which
`git hash-object` fails to hash, aborting the repo-state calculation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

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

Labels

None yet

Projects

Status: Needs triage

Development

Successfully merging this pull request may close these issues.

1 participant