fix: allow non-git directories to be added as projects#2173
Open
bendavid wants to merge 1 commit into
Open
Conversation
getWorktreeRoot used isNotGitRepositoryError to detect non-git directories by regex-matching git's stderr text. Git 2.55+ changed the 'not a git repository' error message, breaking the regex and causing all non-git directory project adds to fail with a generic error. Replace the regex approach with a programmatic exit-code check: git rev-parse --show-toplevel exits 128 when not in a git repository. Use acceptExitCodes: [0, 128] and check the exit code directly, which is stable across git versions and doesn't depend on human-readable error text. Remove the now-unused isNotGitRepositoryError function.
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Adding a non-git folder via "Add project" fails with a generic "Unable to add project" error. Non-git directories are supposed to be supported as projects — the server creates
non_gitprojects, the app handlesisGit: falsethroughout, and there's an e2e test (project-becomes-git.e2e.test.ts) that verifies non-git projects work and can be upgraded to git later.Root cause
getWorktreeRootincheckout-git.tsdetected non-git directories by regex-matching git's stderr error message viaisNotGitRepositoryError. The regex expected:But git 2.55+ changed the message to:
The regex no longer matched, so the error was re-thrown instead of returning
null. This propagated throughgetCheckout→findOrCreateProjectForDirectory→handleProjectAddRequest, causing every non-git project add to fail.Fix
Replace the regex-based
isNotGitRepositoryErrorwith a programmatic exit-code check.git rev-parse --show-toplevelexits with code 128 when the cwd is not inside a git repository — this is a stable contract, not human-readable text that changes between versions.The
acceptExitCodespattern is already used throughout the codebase (e.g.acceptExitCodes: [0, 1]for ref verification). Removed the now-unusedisNotGitRepositoryErrorfunction.Verification
checkout-git.test.tstests pass.checkout-git-rev-parse.test.ts+workspace-git-service.test.tstests pass.git rev-parse --show-toplevelexits 128 for non-git dirs and 0 for git dirs on git 2.55.0.client.addProject("/tmp/paseo-non-git-test")before the fix; the fix resolves it.