Register gitty:// protocol on Windows and prefill Clone dialog from links #64

Merged
Christoph merged 1 commit from installer into main 2026-10-02 20:17:18 +00:00
Owner

This change adds support for a gitty:// URL protocol on Windows and makes Gitty accept such links to prefill the Clone repository dialog. It also updates the installer to register the protocol and updates the app and startup logic to parse and safely handle incoming protocol links.

Key behavior changes

  • Installer (NSIS): the Windows installer now registers a per-user URL protocol handler at HKCU\Software\Classes\gitty that runs ${MAINBINARYNAME}.exe --protocol-url "%1" when a gitty:// link is opened. The installer adds DefaultIcon and URL Protocol entries. Uninstall removes the registry key; updates keep the registration.

  • Protocol parsing (Rust): a new clone_request_from_url function accepts gitty://clone?url=... links and returns a StartupCloneRequest only when the URL strictly matches the expected form and the provided remote looks like an acceptable remote (HTTPS/HTTP/SSH/GIT or user@host:path). The parser rejects malformed, control-char containing, empty, or suspicious values (e.g. file: URLs, multiple url params, flags like --upload-pack, or embedded target/destination). Browser links are explicitly treated as prefill-only: they set the remote URL but do not set a destination or trigger a clone. CLI handling now recognizes --protocol-url and gitty:-prefixed args to create a startup clone request. Repository path parsing (repository_path_from_args) ignores protocol URLs so they will not be interpreted as local destinations.

  • UI (Svelte): the app opens the Clone dialog prefilled when the startup clone request lacks a parent/destination. CloneRepositoryDialog gains an initialRemoteUrl prop and uses it to set the remoteUrl field and select the URL source.

  • Documentation: README.md includes a short section documenting a Forgejo link template (Gitty = gitty://clone?url={url}) and usage notes (URL-encode the repo URL; browser may prompt to open the app; uninstall removes the registration; updates preserve it).

Tests

  • New unit tests were added in startup_repository_tests to verify that:
    • Valid gitty://clone?url=... links prefill the dialog without supplying a local destination or starting a clone.
    • Various invalid gitty:// links are rejected and cannot be interpreted as local paths or CLI clone requests.

No test execution results were provided.

Recommended checks for reviewers

  1. On Windows, run the installer and verify that HKCU\Software\Classes\gitty is created with the expected command and icon entries, and that the uninstaller removes the key. Confirm installer updates do not remove the registration.
  2. Create a gitty://clone?url=<encoded-remote> link and open it from a browser; confirm Gitty opens (or is focused) and the Clone dialog appears with the remote URL filled but no destination selected and no clone started.
  3. Confirm that malformed or disallowed URLs (file: URLs, empty url param, control chars, extra params) are rejected and do not become local paths.
  4. Verify CLI behavior: supplying --protocol-url <url> or starting the app with a gitty:... argument leads to a startup request being parsed, but the app still requires an explicit destination to perform a clone.

Compatibility and risk notes

  • Protocol registration is per-user (HKCU) and only added by the Windows installer. Uninstall removes the registry key; installer updates preserve it.
  • Browser links only prefill the Clone dialog and do not start operations or choose a destination; CLI behavior for starting a clone still requires a local destination as before.
  • The registry changes are straightforward but reviewers should verify proper escaping of the executable path in the NSIS script and that the uninstaller path correctly deletes the registry key in update vs. full uninstall scenarios.

If you want, I can add a short manual QA checklist or a focused integration test plan to exercise the installer+protocol registration end-to-end.

This change adds support for a gitty:// URL protocol on Windows and makes Gitty accept such links to prefill the Clone repository dialog. It also updates the installer to register the protocol and updates the app and startup logic to parse and safely handle incoming protocol links. Key behavior changes - Installer (NSIS): the Windows installer now registers a per-user URL protocol handler at `HKCU\Software\Classes\gitty` that runs `${MAINBINARYNAME}.exe --protocol-url "%1"` when a `gitty://` link is opened. The installer adds `DefaultIcon` and `URL Protocol` entries. Uninstall removes the registry key; updates keep the registration. - Protocol parsing (Rust): a new `clone_request_from_url` function accepts `gitty://clone?url=...` links and returns a StartupCloneRequest only when the URL strictly matches the expected form and the provided remote looks like an acceptable remote (HTTPS/HTTP/SSH/GIT or `user@host:path`). The parser rejects malformed, control-char containing, empty, or suspicious values (e.g. file: URLs, multiple `url` params, flags like `--upload-pack`, or embedded target/destination). Browser links are explicitly treated as prefill-only: they set the remote URL but do not set a destination or trigger a clone. CLI handling now recognizes `--protocol-url` and `gitty:`-prefixed args to create a startup clone request. Repository path parsing (`repository_path_from_args`) ignores protocol URLs so they will not be interpreted as local destinations. - UI (Svelte): the app opens the Clone dialog prefilled when the startup clone request lacks a parent/destination. `CloneRepositoryDialog` gains an `initialRemoteUrl` prop and uses it to set the `remoteUrl` field and select the URL source. - Documentation: `README.md` includes a short section documenting a Forgejo link template (`Gitty = gitty://clone?url={url}`) and usage notes (URL-encode the repo URL; browser may prompt to open the app; uninstall removes the registration; updates preserve it). Tests - New unit tests were added in `startup_repository_tests` to verify that: - Valid `gitty://clone?url=...` links prefill the dialog without supplying a local destination or starting a clone. - Various invalid `gitty://` links are rejected and cannot be interpreted as local paths or CLI clone requests. No test execution results were provided. Recommended checks for reviewers 1. On Windows, run the installer and verify that `HKCU\Software\Classes\gitty` is created with the expected command and icon entries, and that the uninstaller removes the key. Confirm installer updates do not remove the registration. 2. Create a `gitty://clone?url=<encoded-remote>` link and open it from a browser; confirm Gitty opens (or is focused) and the Clone dialog appears with the remote URL filled but no destination selected and no clone started. 3. Confirm that malformed or disallowed URLs (file: URLs, empty url param, control chars, extra params) are rejected and do not become local paths. 4. Verify CLI behavior: supplying `--protocol-url <url>` or starting the app with a `gitty:...` argument leads to a startup request being parsed, but the app still requires an explicit destination to perform a clone. Compatibility and risk notes - Protocol registration is per-user (HKCU) and only added by the Windows installer. Uninstall removes the registry key; installer updates preserve it. - Browser links only prefill the Clone dialog and do not start operations or choose a destination; CLI behavior for starting a clone still requires a local destination as before. - The registry changes are straightforward but reviewers should verify proper escaping of the executable path in the NSIS script and that the uninstaller path correctly deletes the registry key in update vs. full uninstall scenarios. If you want, I can add a short manual QA checklist or a focused integration test plan to exercise the installer+protocol registration end-to-end.
Register a per-user gitty:// URL protocol in the Windows installer and add
runtime parsing to accept browser/opened protocol links. Browser links of the
form gitty://clone?url=<URL> are validated and used to prefill the Clone
dialog's remote URL in the UI, but they do not supply a destination or start a
clone (CLI clone behavior unchanged). The installer shell/open command passes
the raw protocol URL to the app via --protocol-url.

Summary of changes:
- README: document a Forgejo clone-link template and usage notes for gitty://
- nsis-hooks.nsh: write registry keys to register gitty protocol, icon, and
  open command; remove the key on uninstall
- src-tauri/src/main.rs: add clone_request_from_url and wire --protocol-url and
  gitty: arguments into startup handling; reject malformed or dangerous links;
  add unit tests for valid/invalid browser links
- src/App.svelte and CloneRepositoryDialog.svelte: propagate an initialRemoteUrl
  to prefill the clone dialog when a protocol link is received; ensure the
  dialog opens without selecting a destination

Behavioral notes:
- Browser-supplied links only prefill the remote URL; they cannot set a local
  target path or clone flags. CLI behavior (explicit clone destination) is
  unchanged.
Sign in to join this conversation.
No description provided.