rushstack icon indicating copy to clipboard operation
rushstack copied to clipboard

[rush] "Build cache is only supported if running in a Git repository" error thrown inside git repository

Open trusktr opened this issue 6 months ago • 2 comments

Summary

I don't know how to reproduce this. rush build ends with this:

Analyzing repo state... Error calculating the state of the repo. (inner error: Error: git --no-optional-locks exited with code 128:
fatal: Unable to hash inference/thorn_safer/local-deps/pyproto

    at spawnGitAsync (/Users/trusktr/.nvm/versions/node/v22.17.1/lib/node_modules/@microsoft/rush/node_modules/@rushstack/package-deps-hash/lib/getRepoState.js:226:15)
    at async hashFilesAsync (/Users/trusktr/.nvm/versions/node/v22.17.1/lib/node_modules/@microsoft/rush/node_modules/@rushstack/package-deps-hash/lib/getRepoState.js:265:30)
    at async getRepoStateAsync (/Users/trusktr/.nvm/versions/node/v22.17.1/lib/node_modules/@microsoft/rush/node_modules/@rushstack/package-deps-hash/lib/getRepoState.js:324:36)
    at async Promise.all (index 0)
    at async tryGetSnapshotAsync (/Users/trusktr/.nvm/versions/node/v22.17.1/lib/node_modules/@microsoft/rush/node_modules/@microsoft/rush-lib/dist/commons.js:22647:55)
    at async PhasedScriptAction._runInitialPhasesAsync (/Users/trusktr/.nvm/versions/node/v22.17.1/lib/node_modules/@microsoft/rush/node_modules/@microsoft/rush-lib/dist/commons.js:21012:33)
    at async PhasedScriptAction.runAsync (/Users/trusktr/.nvm/versions/node/v22.17.1/lib/node_modules/@microsoft/rush/node_modules/@microsoft/rush-lib/dist/commons.js:20986:37)
    at async PhasedScriptAction.onExecuteAsync (/Users/trusktr/.nvm/versions/node/v22.17.1/lib/node_modules/@microsoft/rush/node_modules/@microsoft/rush-lib/dist/commons.js:19461:16)
    at async PhasedScriptAction._executeAsync (/Users/trusktr/.nvm/versions/node/v22.17.1/lib/node_modules/@microsoft/rush/node_modules/@rushstack/ts-command-line/lib/providers/CommandLineAction.js:64:9)
    at async RushCommandLineParser.onExecuteAsync (/Users/trusktr/.nvm/versions/node/v22.17.1/lib/node_modules/@microsoft/rush/node_modules/@rushstack/ts-command-line/lib/providers/CommandLineParser.js:262:13)). Continuing without diffing files.
DONE (0.20 seconds)

Executing a maximum of 14 simultaneous processes...
Error: Build cache is only supported if running in a Git repository. Either disable the build cache or run Rush in a Git repository.
rush build - Errors! (0.55 seconds)

Repro steps

I'm trying to build as usual, but something in the repo (it is a git repo with a .git folder) is causing Rush to exit with this erroneous error (its a git repo!).

Expected result: Run rush build as usual.

Actual result: The error above.

Details

I've no idea why this is happening. buildCacheEnabled is set to true, and I'm running rush build at the root of a git repo.

Standard questions

Please answer these questions to help us investigate your issue more quickly:

Question Answer
@microsoft/rush globally installed version? yes, 5.153.1
rushVersion from rush.json? 5.153.1
useWorkspaces from rush.json? no, but pnpm-config.json has useWorkspaces:true
Operating system? macOS
Would you consider contributing a PR? Maybe
Node.js version (node -v)? 22.17.0

trusktr avatar Aug 05 '25 21:08 trusktr

The error was happening during an incomplete git merge. I ran git commit to finalize the merge, and that made the error go away.

It would be sweet if the error was something else like "don't run rush build during a merge, commit the merge first".

trusktr avatar Aug 05 '25 21:08 trusktr

@dmichon-msft - thoughts on checking the repo status, perhaps just if something goes wrong?

iclanton avatar Aug 06 '25 16:08 iclanton