Skip to content

Resolve the path before validating it when adding a repository - #22652

Open
francisrath wants to merge 6 commits into
desktop:developmentfrom
francisrath:fix-tilde-path-validation
Open

francisrath wants to merge 6 commits into
desktop:developmentfrom
francisrath:fix-tilde-path-validation

Conversation

@francisrath

@francisrath francisrath commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Closes #5410

Description

Paths starting with ~ can't be added: entering ~/src/my-repo reports "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 and untildify is in this dialog now, but it runs after the validation that rejects the path:

const { path } = this.state
const isValidPath = await this.validatePath(path)   // raw path, still contains ~

if (!isValidPath) {
  this.pathTextBoxRef.current?.focus()
  return                                            // never gets any further
}

const resolvedPath = this.resolvedPath(path)        // untildify happens here

validatePath → getRepositoryType begins with a directoryExists check, and a literal ~/… doesn't exist as far as the file system is concerned, so the result is always missing and the early return means the expansion is never reached.

This validates the resolved path instead. resolvedPath also strips the surrounding quotes added in #23108, so quoted ~ paths work too. The setState inside validatePath still 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:

Entered Before After
~/ghd-tilde-test/my-repo rejected as not a repository adds
~/ghd-tilde-test (a plain folder) rejected still rejected
/Users/…/ghd-tilde-test/my-repo adds adds

The 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.tsx now covers the merged code: ~/repository and "~/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: untildify expands a leading ~ followed by / or \ to os.homedir() on every platform, so on Windows ~\src\repo resolves under C:\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 in clone-repository.tsx, which does url.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

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]>
@github-actions github-actions Bot added external Pull request originating outside of the Desktop core team needs-triage labels Aug 4, 2026
@francisrath
francisrath marked this pull request as ready for review October 15, 2026 18:17
@francisrath
francisrath requested a review from a team as a code owner October 15, 2026 18:17
@github-actions github-actions Bot added ready-for-review Pull Requests that are ready to be reviewed by the maintainers and removed needs-triage labels Oct 15, 2026
@github-actions

Copy link
Copy Markdown
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 help wanted label when possible, as it helps us prioritize and track contributions.

francisrath and others added 2 commits November 4, 2026 08:58
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]>
@francisrath

Copy link
Copy Markdown
Contributor Author

@niik @tidy-dev would one of you be able to take a look when you have a moment? It's a small fix: validate the resolved path, so ~ paths can be added.

#23108 touched the same line, so I merged it in. The two work together, "~/repo" included, and I added tests using the harness from that PR. Thanks!

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

external Pull request originating outside of the Desktop core team ready-for-review Pull Requests that are ready to be reviewed by the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

use of ~ (home directory alias) does not resolve, and no warning message about it

1 participant