Skip to content

test(switch): cover GitLab fork remote lookup across ssh/https - #2596

Merged
max-sixty merged 1 commit into
mainfrom
todos-2-gitlab-protocol
May 4, 2026
Merged

max-sixty merged 1 commit into
mainfrom
todos-2-gitlab-protocol

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Summary

The TODO at src/commands/worktree/switch.rs:226-236 warned that find_remote_by_url could fail when glab's git_protocol setting (ssh vs https) disagreed with how the user's remote is configured, and suggested adding a fallback that converts ssh ↔ https and retries.

That concern is obsolete: find_remote_by_url parses both URLs (the lookup target and each configured remote) into (host, owner, repo) via GitRemoteUrl::parse, then matches on those components. Transport protocol is abstracted away before matching, so a remote configured with [email protected]:foo/bar.git already matches a lookup with https://gitlab.com/foo/bar.git and vice versa.

Implementing the literal fallback would have been dead code (the first lookup already succeeds across protocols). Instead:

  • Remove the obsolete TODO.
  • Add test_find_remote_by_url_cross_protocol (no insteadOf involved) to lock in the cross-protocol behavior so future readers don't re-introduce the fallback.
  • Leave a one-line comment at the call site pointing to the test.

Test plan

  • cargo run -- hook pre-merge --yes (3485 tests pass, lints clean)
  • New unit test covers HTTPS remote / SSH lookup and SSH remote / HTTPS lookup, with a nested GitLab subgroup path
  • Existing test_find_remote_by_url_insteadof still passes

This was written by Claude Code on behalf of @max-sixty

The TODO at the GitLab fork-target lookup site warned that
`find_remote_by_url` would fail when glab's git_protocol setting
disagreed with the user's remote (ssh vs https). That concern is
obsolete: `find_remote_by_url` parses both URLs into (host, owner,
repo) via `GitRemoteUrl::parse` and matches on the parsed components,
so transport protocol no longer affects lookup.

Replace the TODO with a brief comment pointing to a new test that
locks in the cross-protocol behavior, so future readers don't
re-introduce the "try the other protocol" fallback.

Co-Authored-By: Claude <[email protected]>
@max-sixty
max-sixty merged commit a390d7e into main May 4, 2026
27 checks passed
@max-sixty
max-sixty deleted the todos-2-gitlab-protocol branch May 4, 2026 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants