Repository navigation
Resolve the path before validating it when adding a repository - #22652
Open
francisrath wants to merge 6 commits into
Open
francisrath wants to merge 6 commits into
francisrath wants to merge 6 commits into
Conversation
A path like `~/src/my-repo` never validates: `validatePath` checks what was typed, and a literal `~/…` doesn't exist as far as the file system is concerned, so it always comes back missing. The dialog does expand the tilde, but only after validation has already returned early, so it never gets that far. Validate the resolved path instead. The state update still compares against the unresolved path, since that's what the text box holds. Co-Authored-By: Claude Opus 5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
francisrath
marked this pull request as ready for review
October 15, 2026 18:17
Contributor
|
Thanks for your pull request! While it doesn't meet all of our standard requirements, it appears to be a small, focused contribution and has been routed to the team for review. Note: We still encourage linking to an issue with the |
Validation goes through resolvedPath, which now also strips the quotes handled upstream, so quoted and ~ paths both validate as they'll be added. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The dialog gained a test harness upstream, so this no longer needs a real repository under the home directory. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Contributor
Author
This branch has not been deployed
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.
Closes #5410
Description
Paths starting with
~can't be added: entering~/src/my-reporeports "This directory does not appear to be a Git repository" and offers to create one there, while the same repository adds fine by its absolute path.@shiftkey diagnosed this back in 2018 — we don't resolve
~. The code has moved on since then anduntildifyis in this dialog now, but it runs after the validation that rejects the path:validatePath→getRepositoryTypebegins with adirectoryExistscheck, and a literal~/…doesn't exist as far as the file system is concerned, so the result is alwaysmissingand the early return means the expansion is never reached.This validates the resolved path instead.
resolvedPathalso strips the surrounding quotes added in #23108, so quoted~paths work too. ThesetStateinsidevalidatePathstill compares against the unresolved path, since that's what the text box holds — passing the resolved path in as the argument would stop that guard ever matching and quietly break the warning updates.The symptom has drifted since 2018, for anyone searching: the Add Repository button is no longer disabled, so it looks clickable and simply doesn't appear to do anything.
Testing
Verified in a development build against a repository at
~/ghd-tilde-test/my-repo:~/ghd-tilde-test/my-repo~/ghd-tilde-test(a plain folder)/Users/…/ghd-tilde-test/my-repoThe middle row is the one worth having: resolving the path doesn't make validation accept things it shouldn't.
The table is from a manual run before #23108 landed.
repository-directory-exceptions-test.tsxnow covers the merged code:~/repositoryand"~/repository"must both be validated and added as the path under the home directory. Those tests fail without this change.The code path isn't platform-specific, despite the macOS label on #5410:
untildifyexpands a leading~followed by/or\toos.homedir()on every platform, so on Windows~\src\reporesolves underC:\Users\<name>. I've only tested on macOS.Something adjacent I noticed
Leading or trailing whitespace around the path fails too, and the leading case is a bit unpleasant:
Path.resolve('/', ' /Users/me/repo')treats the space-prefixed string as relative and yields/ /Users/me/repo, so it silently becomes a different path rather than failing honestly. Trailing whitespace just doesn't resolve.I've left it out on purpose since it's outside what #5410 describes, and trimming is a judgement call — leading and trailing spaces are legal in POSIX filenames, so
.trim()would make a directory genuinely named"repo "unreachable by typing. There's some precedent inclone-repository.tsx, which doesurl.trim(). Happy to add it here or open a separate issue, whichever you prefer.Screenshots
N/A — no visual change.
Release notes
Notes: [Fixed] Paths beginning with
~can now be used when adding a local repository