Skip to content

fix(git): stop reading a remote URL's port as part of the repository path - #16723

Merged
VascoSch92 merged 5 commits into
OpenHands:mainfrom
MarMarLabs:fix/git-remote-url-port
Aug 20, 2026
Merged

VascoSch92 merged 5 commits into
OpenHands:mainfrom
MarMarLabs:fix/git-remote-url-port

Conversation

@MarMarLabs

@MarMarLabs MarMarLabs commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

HUMAN:

Ran the parser test file on this branch, and all 13 cases pass. Put the version
of parse-git-remote-url.ts from main back, and the two new cases fail, showing
"2222/owner/repo" instead of "owner/repo".
What convinced me this is worth fixing is that the browse link in the git sync
panel is built directly from that value, so the port ends up in the URL you
click.

AGENT:

Ran the parser against remote URLs that carry an explicit port, before and after the change, on a clean npm ci checkout.

$ # BEFORE — upstream/main, with the two new cases present
$ npx vitest run __tests__/utils/parse-git-remote-url.test.ts
 × parses ssh:// URLs that carry an explicit port
 × parses http(s) URLs that carry credentials and a port
AssertionError: expected '2222/owner/repo' to be 'owner/repo'
AssertionError: expected '8080/owner/repo' to be 'owner/repo'
 Tests  2 failed | 11 passed (13)

$ # AFTER — this branch
$ npx vitest run __tests__/utils/parse-git-remote-url.test.ts
 Test Files  1 passed (1)
      Tests  13 passed (13)

No regressions across the surrounding suites, same clean checkout:

$ npx vitest run __tests__/utils __tests__/hooks
 Test Files  153 passed (153)
      Tests  969 passed | 4 skipped (973)

Why the shorthand branch was claiming these URLs. [^@\s]+ happily matches ssh://git, so
ssh://[email protected]:2222/owner/repo.git was treated as SCP shorthand with host
git.example.com and path 2222/owner/repo.git:

$ node -e 'const m = "ssh://[email protected]:2222/owner/repo.git".match(/^[^@\s]+@([^:\s]+):(.+)$/); console.log("host:", m[1]); console.log("path:", m[2]);'
host: git.example.com
path: 2222/owner/repo.git

Component-level proof of the user-visible effect. git-sync-overview-section.test.tsx already
covers a self-hosted forge's port over https and an ssh shorthand remote, but never the two
together. Adding that case pins the rendered anchor's href:

$ # BEFORE — upstream/main
$ npx vitest run src/components/features/automations/git-sync/git-sync-overview-section.test.tsx
 × keeps a self-hosted forge's path when ssh:// carries a port
Expected the element to have attribute:
  href="https://git.example.com/org/repo"
Received:
  href="https://git.example.com/2222/org/repo"
 Tests  1 failed | 7 passed (8)

$ # AFTER — this branch
 Test Files  1 passed (1)
      Tests  8 passed (8)

That is the actual link a user clicks in the git sync panel, so the port was landing in the
navigation target.

Confirmed on a running stack, not just in tests. Captured from the real /automations/git-sync
route against a local agent server 1.42.1 / automation backend 1.8.0, health {"status":"ok"},
git sync clean (no last_error, no sync in progress, zero pending changes), with the repository
configured as ssh://[email protected]:2222/org/repo.git. Reading
[data-testid="git-sync-repo-link"] live in the DOM:

BEFORE (main)   text: ssh://[email protected]:2222/org/repo.git
                href: https://git.example.com/2222/org/repo

AFTER  (fix)    text: ssh://[email protected]:2222/org/repo.git
                href: https://git.example.com/org/repo

The rendered text is the configured remote either way, so the panel looks identical in a
screenshot. The change is the anchor's href, which is why the evidence here is the DOM value and
the assertion above rather than an image.

User-visible effect. git-sync-overview-section.tsx:32 builds the browse link as
`https://${parsed.host}/${parsed.repository}`. Read live from the running page, that anchor's
href is https://git.example.com/2222/org/repo before the change and
https://git.example.com/org/repo after (screenshots above). That function's doc comment already states it keeps
"non-default ports intact" and rebuilds ssh:// remotes "over https from the parsed host and
repository", so this makes the code match the documented intent. use-local-git-info.ts:68
surfaces repository directly, so the displayed repo name was wrong too.

Plain [email protected]:owner/repo.git shorthand is unaffected and is covered by an existing test.


Why

parseGitRemoteUrl read the port of a scheme'd remote URL as the first segment of the repository
path, so anyone whose remote is a self-hosted forge on a non-default SSH port (2222, 7999) got a
wrong repository name and a broken "browse repository" link.

Summary

  • Skip the SCP-shorthand branch when the URL contains ://, letting the existing new URL() branch
    parse it.
  • Add two cases to __tests__/utils/parse-git-remote-url.test.ts covering ssh:// with a port and
    http:// with credentials and a port.
  • Add a case to git-sync-overview-section.test.tsx pinning the browse link's href for an
    ssh:// remote on a custom port.

Issue Number

Fixes #16722

How to Test

npm ci
npx vitest run __tests__/utils/parse-git-remote-url.test.ts

13 cases pass. Reverting src/utils/parse-git-remote-url.ts to main and re-running fails exactly
the two new cases with expected '2222/owner/repo' to be 'owner/repo'.

Video/Screenshots

Before (main) — the anchor's href carries the port as a path segment:
SAFE-cropped-before-main

After (this branch) — the port is gone from the href; Chrome's status bar shows the resolved destination:
SAFE-cropped-after-fix

The rendered link text is the configured remote in both, so the panel looks the same.
The change is the anchor's href, visible in the DevTools Elements panel.

…path

The SCP-shorthand branch ran before the URL parser, and its regex matches
a URL that already carries a scheme, so the port in
`ssh://git@host:2222/owner/repo.git` was consumed as the first path
segment and `repository` came back as `2222/owner/repo`.

Skip the shorthand branch when the URL contains a scheme and let the
existing `new URL()` branch handle it. Plain `git@host:owner/repo`
shorthand is unchanged.
@github-actions github-actions Bot added the type: fix A bug fix label Aug 19, 2026
The overview section already covers a self-hosted forge's port over https
and an ssh shorthand remote, but never the two together, which is the
combination that produced a wrong href.
…path

Restores the parser change, which was dropped from the previous commit.

The SCP-shorthand branch ran before the URL parser, and its regex matches
a URL that already carries a scheme, so the port in
`ssh://git@host:2222/owner/repo.git` was consumed as the first path
segment and `repository` came back as `2222/owner/repo`.
@DevinVinson
DevinVinson requested a review from VascoSch92 August 19, 2026 15:46
@all-hands-bot

Copy link
Copy Markdown
Collaborator

🚦 CI is currently failing on this PR's latest commit.

Please fix the failing checks before OpenHands reviews it - this is re-checked automatically once you push a new commit. (A maintainer can also request @all-hands-bot as a reviewer to have it reviewed regardless of CI status.)

This is an automated check - no AI was used to generate this comment.

@MarMarLabs

Copy link
Copy Markdown
Contributor Author

All functional checks pass on this PR: test-and-build (ubuntu and windows), mock-llm-e2e (16/16), check-pr-artifacts, detect-pr-changes, prepare-test-matrix, pr-title.

Validate PR description reports two errors, and I would rather explain them than paper over them.

"touches frontend code but the description has no screenshot or video." The change is to parseGitRemoteUrl, a string parser with no visual surface, so there is no screenshot that would show a reviewer anything real. Rather than attach an unrelated image, I added a case to git-sync-overview-section.test.tsx that pins the rendered anchor's href — the actual link a user clicks:

Expected: href="https://git.example.com/org/repo"
Received: href="https://git.example.com/2222/org/repo"

That file already covered a self-hosted forge's port over https and an ssh shorthand remote, but never the two together, which is the combination that produced the wrong link. Happy to attach a UI capture instead if you would prefer one; reaching that panel needs a live agent-server with a git-sync automation configured against an ssh://…:2222/ remote, so I did not want to stage something misleading.

ready-for-dev on #16722. Applying the label needs triage permission I do not have.

Glad to restructure the issue or this PR if you would rather it read a different way.

Guarding the shorthand branch on `://` keeps the port out of the
repository path, but it also sends every scheme'd URL whose colon segment
is not numeric into `new URL()`, which throws: `ssh://git@host:owner/repo`
and `git+ssh://git@host:owner/repo` went from parsing to returning null,
which drops the browse link and, through use-local-git-info, the repo and
provider that git-control-bar gates its actions on.

Ordering the two parsers instead handles both shapes in one branch, and
also fixes IPv6 remotes, where the shorthand regex reduced the host of
`ssh://git@[::1]:2222/owner/repo.git` to `[`.

Cover the colon-segment-is-a-path case, split the credentials test into
its http and https:// user:password forms, and name the git-sync test for
the port behaviour it actually asserts.

@VascoSch92 VascoSch92 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR.

I just added a commit to fix a couple of nits.

Otherwise, LGTM

@github-actions

Copy link
Copy Markdown
Contributor

✅ Mock-LLM E2E Tests

16/16 passed

Commit: 24356b75 · Workflow run · Test artifacts

Details
Status Test Duration
✅ automations/mock-llm-automation.spec.ts › mock-LLM automation lifecycle › step 1: setup LLM profile and register automation trajectory 6.6s
✅ automations/mock-llm-automation.spec.ts › mock-LLM automation lifecycle › step 2: create automation and dispatch run via the UI 29.6s
✅ automations/mock-llm-automation.spec.ts › mock-LLM automation lifecycle › step 3: verify automation and run on the automations page 5.9s
✅ automations/mock-llm-preset-automation.spec.ts › preset automation → slash command conversation › automation card sends the correct slash command to a conversation 15.8s
✅ automations/mock-llm-preset-automation.spec.ts › preset automation → slash command conversation › direct slash command from home page triggers skill activation 13.6s
✅ files/mock-llm-files-and-git.spec.ts › files tab, conversation overview git, and browser tab › step 1: ensure mock LLM profile is configured 6.3s
✅ files/mock-llm-files-and-git.spec.ts › files tab, conversation overview git, and browser tab › step 2: start conversation and attach workspace metadata 12.5s
✅ files/mock-llm-files-and-git.spec.ts › files tab, conversation overview git, and browser tab › step 3: conversation overview shows workspace and git identity 26.1s
✅ files/mock-llm-files-and-git.spec.ts › files tab, conversation overview git, and browser tab › step 4: commits tab opens for attached workspace 5.9s
✅ files/mock-llm-files-and-git.spec.ts › files tab, conversation overview git, and browser tab › step 5: browser tab shows empty state 6.3s
✅ files/mock-llm-files-and-git.spec.ts › files tab, conversation overview git, and browser tab › step 6: files tab defaults to file-tree view without attached workspace 8.0s
✅ regressions/mock-llm-ui-regressions.spec.ts › UI regressions › scopes standalone styles to the agent-server-ui shell 1.4s
✅ regressions/mock-llm-ui-regressions.spec.ts › UI regressions › renders critic results on agent messages and finish actions 1.6s
✅ regressions/mock-llm-ui-regressions.spec.ts › UI regressions › loads older events when scrolling up 2.0s
✅ regressions/mock-llm-ui-regressions.spec.ts › UI regressions › selected workspace persists after navigating away and returning 2.5s
✅ regressions/mock-llm-ui-regressions.spec.ts › UI regressions › cleared sessionStorage yields empty workspace selection 1.2s

Posted by the Mock-LLM E2E workflow · results are deterministic (scripted LLM responses)

@all-hands-bot

Copy link
Copy Markdown
Collaborator

🚦 CI is currently failing on this PR's latest commit.

Please fix the failing checks before OpenHands reviews it - this is re-checked automatically once you push a new commit. (A maintainer can also request @all-hands-bot as a reviewer to have it reviewed regardless of CI status.)

This is an automated check - no AI was used to generate this comment.

@VascoSch92
VascoSch92 merged commit 4a8cabc into OpenHands:main Aug 20, 2026
20 of 21 checks passed
@openhands-release-bot openhands-release-bot Bot added the released: v1.15.0 Shipped in v1.15.0 label Aug 21, 2026
@openhands-release-bot

Copy link
Copy Markdown
Contributor

🚀 Released in v1.15.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released: v1.15.0 Shipped in v1.15.0 type: fix A bug fix

Projects

None yet

3 participants