Skip to content

gix-url parses SSH aliases as file paths #933

@niklaswimmer

Description

@niklaswimmer

Duplicates

  • I have searched the existing issues

Current behavior 😯

The parsing of URLs in gix-url does not respect the user's SSH config file. Instead, it classifies abbreviated SSH URLs as file paths.

For example, in my SSH config I have the following entry defined to abbreviate [email protected] to just github (and to choose a specific key file for this host).

Host github
    User git
    Hostname github.com
    IdentityFile ~/.ssh/git/github_rsa

Cloning with Git then looks like git clone github:byron/gitoxide. If I try gix clone github:byron/gitoxide I get the following error:

Error: Could not verify that "/tmp/github:byron/gitoxide" url is a valid git directory before attempting to use it

Caused by:
    0: Could not retrieve metadata of "/tmp/github:byron/gitoxide/.git"
    1: No such file or directory (os error 2)

The problem seems to stem from the URL parsing logic which marks any URL without an @ or . as a file path:

https://github.com/Byron/gitoxide/blob/2087032b5956dcd82bce6ac57e530e8724b57f17/gix-url/src/parse.rs#L39-L45

I first noticed this issue with ein tool organize, which skips all file URLs silently because they do not have a host specified: https://github.com/Byron/gitoxide/blob/2087032b5956dcd82bce6ac57e530e8724b57f17/gitoxide-core/src/organize.rs#L162-L165

Expected behavior 🤔

I would expect gitoxide to parse such abbreviated URLs correctly. I am not sure exactly how though.

I looked at the Git source and to me it seems like they simply never check for the @ character (see this function here which is then used here)?

However, looking at gitoxide's tests, it seems to me like the current behavior is the expected one: https://github.com/Byron/gitoxide/blob/2087032b5956dcd82bce6ac57e530e8724b57f17/gix-url/tests/parse/ssh.rs#L68

Given that, the only solution I can think of is to look at the SSH config to determine if we are dealing with an SSH alias?

If we can find an acceptable solution I would be happy to contribute the implementation myself :)

Steps to reproduce 🕹

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    acknowledgedan issue is accepted as shortcoming to be fixedhelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions