Skip to content

Drop the port from remote-derived hosts so glab --hostname accepts them - #165

Merged
cpojer merged 2 commits into
nkzw-tech:mainfrom
oskarnyc:fix/remote-url-port
Aug 31, 2026
Merged

Drop the port from remote-derived hosts so glab --hostname accepts them#165
cpojer merged 2 commits into
nkzw-tech:mainfrom
oskarnyc:fix/remote-url-port

Conversation

@oskarnyc

Copy link
Copy Markdown
Contributor

fix: drop port from remote host so glab --hostname accepts it

parseRemoteUrl used URL.host for ssh:// / https:// remotes, which includes the port
(ssh://git@gitlab.example.com:2222/group/project.gitgitlab.example.com:2222). That value is passed
to glab api --hostname, which rejects any host:portError parsing --hostname: invalid hostname
and codiff mr <n> fails with "Unable to read repository" on such GitLab instances.

Use URL.hostname instead. No behaviour change for remotes without a port (host === hostname);
the scp-style branch already had no port.

Test added: parseRemoteUrl('ssh://git@gitlab.example.com:2222/group/project.git')host: 'gitlab.example.com'.

Repro

Any repository whose origin remote is an ssh:// (or https://) URL with a port, e.g.

git remote set-url origin ssh://git@gitlab.example.com:2222/group/project.git
codiff mr 1

Result (desktop window):

Unable to read repository
Error invoking remote method 'codiff:getRepositoryState':
Error: ERROR Error parsing --hostname: invalid hostname.

glab itself works fine in the same repo (glab mr view 1 resolves the host from the remote).

parseRemoteUrl used URL.host for ssh:// and https:// remotes, which
includes the port (ssh://git@gitlab.example.com:2222/group/project.git
-> gitlab.example.com:2222). That value is passed to `glab api
--hostname`, which rejects any host:port, so `codiff mr <n>` failed
with "Unable to read repository" on GitLab instances whose remotes
carry a custom port.

Use URL.hostname instead. No behaviour change for remotes without a
port, and the scp-style branch already had none. Adds regression tests
for ssh/https remotes with ports.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@cpojer

cpojer commented Aug 31, 2026

Copy link
Copy Markdown
Member

Yo! Thanks for the contribution. This doesn't work as it strips the port both from ssh and https protocols, but if you strip them from https, it will break the identifier. Can you limit port stripping to ssh and update the https test?

An explicit port on https:// remotes is part of the instance
identifier and must be kept; only the SSH transport port is dropped.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@oskarnyc

Copy link
Copy Markdown
Contributor Author

Good catch, thanks — port stripping is now limited to ssh:// remotes (transport port), while an explicit port on https:// remotes is kept as part of the instance identifier. The https test now asserts the port is preserved. 11/11 passing.

@cpojer
cpojer merged commit 2fb25fe into nkzw-tech:main Aug 31, 2026
@cpojer

cpojer commented Aug 31, 2026

Copy link
Copy Markdown
Member

Thanks!

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