forgejo-contrib/forgejo-cli
20
407
Fork
You've already forked forgejo-cli
51

Resolve ssh host names with ssh config #462

Merged
LordMZTE merged 2 commits from tpikonen/forgejo-cli:resolve-ssh-host into main 2026年05月18日 13:31:52 +02:00
Contributor
Copy link

Changes Made

I usually set up my remotes with the URL set to something like codeberg:tpikonen/project.git, where codeberg is an entry in .ssh/config with the full hostname and key etc. Currently fj does not work at all with this kind of URLs, and even setting the host on the command line (with --host) does not help.

The solution is to dig into the SSH config file to resolve the true hostname in order to find the API URL. This MR implements that.

Code of Conduct

  • I agree to act in accordance with the CoC & AI Agreement.
  • This contribution was not generated by an LLM, even in part.
### Changes Made I usually set up my remotes with the URL set to something like `codeberg:tpikonen/project.git`, where `codeberg` is an entry in `.ssh/config` with the full hostname and key etc. Currently `fj` does not work at all with this kind of URLs, and even setting the host on the command line (with `--host`) does not help. The solution is to dig into the SSH config file to resolve the true hostname in order to find the API URL. This MR implements that. ### Code of Conduct - [x] I agree to act in accordance with the CoC & AI Agreement. - [x] This contribution was not generated by an LLM, even in part.
tpikonen force-pushed resolve-ssh-host from 426d9af741
All checks were successful
ci/woodpecker/pr/check-typos Pipeline was successful
ci/woodpecker/pr/check Pipeline was successful
to bb3c9b29d1
All checks were successful
ci/woodpecker/pr/check-typos Pipeline was successful
ci/woodpecker/pr/check Pipeline was successful
2026年05月14日 16:18:22 +02:00
Compare
LordMZTE requested changes 2026年05月16日 22:50:06 +02:00
Dismissed
src/main.rs Outdated
@ -254,1 +264,3 @@
})
url=url::Url::parse(&new_s)?
}
ifurl.host().is_none(){
Collaborator
Copy link

Use something like let Some(host) = url.host_str() else return Ok(url); here instead, so we can use the value later without having to unwrap.

Use something like `let Some(host) = url.host_str() else return Ok(url);` here instead, so we can use the value later without having to `unwrap`.
Author
Contributor
Copy link

The hostname replacing code is now wrapped in if let Some(host_str).

The hostname replacing code is now wrapped in `if let Some(host_str)`.
tpikonen marked this conversation as resolved
src/main.rs Outdated
@ -255,0 +270,4 @@
ifletSome(ssh_config)=get_ssh_config(){
lethost_params=ssh_config.query(url.host_str().unwrap());
ifletSome(host_name)=host_params.host_name{
url.set_host(Some(&host_name))?;
Collaborator
Copy link

SSH supports a niche feature where the HostName option may contain %h which will be substituted for the specified Host, for example:

Host codeberg
 HostName %h.org
 User git

This doesn't handle that, resulting in this panic for a fj repo view:

thread 'main' (66379) panicked at src/repo.rs:188:22:
should always be valid: IdnaError
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
SSH supports a niche feature where the `HostName` option may contain `%h` which will be substituted for the specified `Host`, for example: ``` Host codeberg HostName %h.org User git ``` This doesn't handle that, resulting in this panic for a `fj repo view`: ``` thread 'main' (66379) panicked at src/repo.rs:188:22: should always be valid: IdnaError note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace ```
Author
Contributor
Copy link

Thanks for spotting this. The code now runs replace() over the Hostname which does what is expected, but does not catch unsupported percent expansion chars or other errors. I suppose these errors will trigger ssh or git earlier, so we don't need to worry about them.

Thanks for spotting this. The code now runs `replace()` over the `Hostname` which does what is expected, but does not catch unsupported percent expansion chars or other errors. I suppose these errors will trigger ssh or git earlier, so we don't need to worry about them.
LordMZTE marked this conversation as resolved
tpikonen force-pushed resolve-ssh-host from bb3c9b29d1
All checks were successful
ci/woodpecker/pr/check-typos Pipeline was successful
ci/woodpecker/pr/check Pipeline was successful
to 0796529b55
All checks were successful
ci/woodpecker/pr/check-typos Pipeline was successful
ci/woodpecker/pr/check Pipeline was successful
2026年05月18日 13:07:49 +02:00
Compare
Cyborus added this to the v0.6.0 milestone 2026年06月22日 06:31:50 +02:00
Sign in to join this conversation.
No reviewers
Labels
Clear labels
Kind/Breaking
Breaking change that won't be backward compatible
Kind/Bug
Something is not working
Kind/Design
Discussion about UI/UX design
Kind/Documentation
Documentation changes
Kind/Enhancement
Improve existing functionality
Kind/Feature
New functionality
Kind/Security
This is security issue
Kind/Testing
Issue or pull request related to testing
Kind/Upstream
This is an issue with upstream software (Forgejo) that is probably not our fault
Priority
Critical
The priority is critical
Priority
High
The priority is high
Priority
Low
The priority is low
Priority
Medium
The priority is medium
Reviewed
Confirmed
Issue has been confirmed
Reviewed
Duplicate
This issue or pull request already exists
Reviewed
Invalid
Invalid issue
Reviewed
Won't Fix
This issue won't be fixed
Status
Abandoned
Somebody has started to work on this but abandoned work
Status
Blocked
Something is blocking this issue or pull request
Status
Need More Info
Feedback is required to reproduce issue or to continue work
Suspicious
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
forgejo-contrib/forgejo-cli!462
Reference in a new issue
forgejo-contrib/forgejo-cli
No description provided.
Delete branch "tpikonen/forgejo-cli:resolve-ssh-host"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?