Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to parse Git repositories with insteadOf and pushInsteadOf URI "rewrites" #253

Open
hyperupcall opened this issue Oct 10, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@hyperupcall
Copy link

hyperupcall commented Oct 10, 2023

Hello!

With the following remote configuration:

$ git remote -v
me git@github.com:reconquest/shdoc (fetch)
me git@github.com:reconquest/shdoc (push)

Clicking the "View Repository" button yields https://reconquest/shdoc - I expected it to redirecredirect to https://github.com/reconquest/shdoc.

With the following remote configuration:

#!/usr/bin/env sh
git init

# GitHub allows for re-writing remote URls on the fly with 'insteadOf' and 'pushInsteadOf' fields.
# This is what trips up vscord. Normally, these are globally configured.
git config --local --add url.'git@github.com:'.insteadOf 'gh:'
git config --local --add url.'git@github.com:'.pushInsteadOf 'gh:'
git remote add me gh:fox-projects/repro-vscode-weird-url

# vscord seems to require a "minimum git history" for showing the "View Repository" button.
# This sets that up.
touch file.txt && git add file.txt && git commit --no-edit --no-template --allow-empty-message
git commit --no-edit --no-template --allow-empty --allow-empty-message
$ git remote -v
me      git@github.com:fox-projects/repro-vscode-weird-url (fetch)
me      git@github.com:fox-projects/repro-vscode-weird-url (push)
$ cat .git/config
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[url "git@github.com:"]
        insteadOf = gh:
        pushInsteadOf = gh:
[remote "me"]
        url = gh:fox-projects/repro-vscode-weird-url
        fetch = +refs/heads/*:refs/remotes/me/*

It seems that there is a parsing error when parsing the value of remote.me.url. You might useful a similar issue/fix I made at xournalpp/xournalpp.

Clicking the "View Repository" button yields https://fox-projects/repro-vscode-weird-url - I expected it to redirect to https://github.com/fox-projects/repro-vscode-weird-url.

@xhayper xhayper added the bug Something isn't working label Oct 10, 2023
@nick22985
Copy link
Collaborator

nick22985 commented Oct 12, 2023

Hey @hyperupcall,
Going to need some more information. What is the me in the git remote. I have never seen this before. When I ssh clone the repo git clone git@github.com:reconquest/shdoc.git
When I do git remote -v I get back this and my view repository button works

origin  git@github.com:reconquest/shdoc.git (fetch)
origin  git@github.com:reconquest/shdoc.git (push)

@hyperupcall
Copy link
Author

hyperupcall commented Oct 12, 2023

I use me instead of origin - it seems the issue was that I am using a non-standard default-remote name, and not that the remote URL is not SSH-style?

@nick22985
Copy link
Collaborator

Also looking at this it seems to work for me when using me for the git remote

 ╰─λ git remote -v
me      git@github.com:reconquest/shdoc (fetch)
me      git@github.com:reconquest/shdoc (push)

@hyperupcall
Copy link
Author

hyperupcall commented Oct 12, 2023

Interesting - this definitely isn't the first time I have come across this issue, but I am suddently unable to reproduce. I'll see if I can find a better repro.

@hyperupcall
Copy link
Author

hyperupcall commented Oct 12, 2023

Okay so I found an actual repro:

#!/usr/bin/env sh
git init

# GitHub allows for re-writing remote URls on the fly with 'insteadOf' and 'pushInsteadOf' fields.
# This is what trips up vscord. Normally, these are globally configured.
git config --local --add url.'git@github.com:'.insteadOf 'gh:'
git config --local --add url.'git@github.com:'.pushInsteadOf 'gh:'
git remote add me gh:fox-projects/repro-vscode-weird-url

# vscord seems to require a "minimum git history" for showing the "View Repository" button.
# This sets that up.
touch file.txt && git add file.txt && git commit --no-edit --no-template --allow-empty-message
git commit --no-edit --no-template --allow-empty --allow-empty-message
$ git remote -v
me      git@github.com:fox-projects/repro-vscode-weird-url (fetch)
me      git@github.com:fox-projects/repro-vscode-weird-url (push)
$ cat .git/config
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
[url "git@github.com:"]
        insteadOf = gh:
        pushInsteadOf = gh:
[remote "me"]
        url = gh:fox-projects/repro-vscode-weird-url
        fetch = +refs/heads/*:refs/remotes/me/*

It seems that there is a parsing error when parsing the value of remote.me.url. You might useful a similar issue/fix I made at xournalpp/xournalpp.

@hyperupcall hyperupcall changed the title Link parsing breaks with SSH-style Git Remotes Unable to parse Git repositories with insteadOf and pushInsteadOf URI "rewrites" Oct 12, 2023
@xhayper
Copy link
Collaborator

xhayper commented Oct 12, 2023

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants