fix: support SSH remotes with non-standard ports (#761)

The SSH host matching logic in contextFromLocalRepo only compared
exact host:port combinations. This failed for SSH remotes using
non-standard ports because the login SSH host configuration typically
stores just the hostname without the port.

This change allows matching both the full host:port string and the
hostname-only version against the configured SSH host, enabling
tea to work with SSH remotes on non-standard ports.

Fixes issue where commands requiring RemoteRepo failed with
'Remote repository required' error when using SSH on custom ports.

Signed-off-by: JD Daniels <jd@danielsdynamic.ca>

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Reviewed-on: https://gitea.com/gitea/tea/pulls/761
Reviewed-by: techknowlogick <techknowlogick@noreply.gitea.com>
Reviewed-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: JD Daniels <jd@danielsdynamic.ca>
Co-committed-by: JD Daniels <jd@danielsdynamic.ca>
This commit is contained in:
JD Daniels
2025-06-07 03:21:11 +00:00
committed by Lunny Xiao
parent 177b7397f3
commit 5420af1dfa

View File

@ -222,7 +222,7 @@ func contextFromLocalRepo(repoPath, remoteValue string) (*git.TeaRepo, *config.L
return repo, &l, strings.TrimSuffix(path, ".git"), nil
}
} else if strings.EqualFold(p.Scheme, "ssh") {
if sshHost == p.Host {
if sshHost == p.Host || sshHost == p.Hostname() {
return repo, &l, strings.TrimLeft(p.Path, "/"), nil
}
}