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

Commit hyperlink not working 🐛 #1628

Open
porridgewithraisins opened this issue Feb 17, 2024 · 11 comments
Open

Commit hyperlink not working 🐛 #1628

porridgewithraisins opened this issue Feb 17, 2024 · 11 comments

Comments

@porridgewithraisins
Copy link

porridgewithraisins commented Feb 17, 2024

I have

[delta]
  hyperlinks = true

in my ~/.gitconfig

[remote "origin"]
        url = https://github.com/porridgewithraisins/e2ee.js
        fetch = +refs/heads/*:refs/remotes/origin/*

in my ~/e2ee.js/.git/config

Files are hyperlinked to vscode as I have set hyperlinks-file-link-format to the vscode:// handler.

However, the commit hash isn't rendering as a hyperlink.

image

cmd+clicking it doesnt work either, fwiw

Also, the hyperlinks don't render in git blame output either.

I am using iterm, zsh here.

@gczajkowskiTT
Copy link

Same for me

@dandavison
Copy link
Owner

Hi @porridgewithraisins, @gczajkowskiTT let's look at the raw bytes that delta's emitting. Can you post the output of

git show | delta | cat -A

(or bat -A if you have bat installed).

@gczajkowskiTT
Copy link

gczajkowskiTT commented Nov 11, 2024

In Linux under Kitty (which is closest to functioning)

<E2><90><8A>
<E2><90><8A>
<E2><90>[34m\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}<E2><90>[0m<E2><90>[34m\u{2510[34m[0m[34m}<E2><90>[0m<E2><90><8A>
<E2><90>[31m\u{2022}<E2><90>[0m<C2><B7><E2><90>8;;file:///proj_soc/user_dev/gczajkowski/ttdelivery/.gitignore<E2><90><E2><90>[31m.gitignore<E2><90>[0m:<E2><90>[38;2;6;122;0m1<E2><90>[0m<E2>
[31m[0m[31m[0m[38;2;6;122;0m[0m<90>8;;<E2><90>:<C2><B7><E2><90>[34m\u{2502}<E2><90>[0m<E2><90><8A>
<E2><90>[34m\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}\u{2500}<E2><90>[0m<E2><90>[34m\u{2518[34m[0m[34m}<E2><90>[0m<E2><90><8A>
<E2><90>[38;2;117;113;94m#<C2><B7>Linux<E2><90>[0m<E2><90><8A>
image

@porridgewithraisins
Copy link
Author

porridgewithraisins commented Nov 12, 2024

I now use a linux laptop (kitty terminal) and it works for me. However, in the few months I used a mac, it did not work at all (in iterm and in kitty). Not able to test now unfortunately.

@dandavison
Copy link
Owner

Has anyone observed that the commit hyperlink doesn't work while other hyperlinks do work? Or are you saying that all hyperlinks (commit, files, line numbers) don't work when there's a problem?

Also if the latter, are you using tmux?

@gczajkowskiTT
Copy link

gczajkowskiTT commented Nov 12, 2024

No hyperlinks are working for me and this is without tmux. Part of the problem looked to be git delta.features = decorations .. as it effected the 'shell output code' .. so disabled it, however it still mostly garbled

@dandavison
Copy link
Owner

No hyperlinks are working for me and this is without tmux

If you do

printf '\e]8;;vscode://file//Users/jaminthornsberry/.gitconfig:10\e\\Take me to git config!\e]8;;\e\n'

then that hyperlink works, right?

If so, then if you capture the bytes emitted by delta (git show | delta | hexyl or cat -A etc) and compare to that printf, do you see a difference?

@gczajkowskiTT
Copy link

printf '\e]8;;vscode://file//Users/jaminthornsberry/.gitconfig:10\e\\Take me to git config!\e]8;;\e\n'
then that hyperlink works, right?

Yes, specifically in VSCode terminal in MacOS. But I can't use these for Linux links.

Hi @porridgewithraisins, @gczajkowskiTT let's look at the raw bytes that delta's emitting. Can you post the output of

git show | delta | cat -A

No such option in MacOS cat
$ git show | delta | cat -A
cat: illegal option -- A


(or `bat -A` if you have bat installed).

With bat -A under VSCode in MacOS there is no link
image

@dandavison
Copy link
Owner

dandavison commented Nov 12, 2024

With bat -A under VSCode in MacOS there is no link

Hmm. I haven't yet come up with a hypothesis for why that would be. It's not the case in my VSCode terminal on MacOS:

image

Here's the code. Can you think what might be going on? It's definitely finding your git config is it? The code shows that the hyperlink will be added if the hyperlink format setting is in effect or if it can find git config and find a git remote for the repo. Are you talking about a situation where the commit hyperlink works fine in a standard terminal emulator on the same machine and then suddenly stops working in VSCode?

pub fn format_commit_line_with_osc8_commit_hyperlink<'a>(
line: &'a str,
config: &Config,
) -> Cow<'a, str> {
if let Some(commit_link_format) = &config.hyperlinks_commit_link_format {
COMMIT_LINE_REGEX.replace(line, |captures: &Captures| {
let prefix = captures.get(1).map(|m| m.as_str()).unwrap_or("");
let commit = captures.get(2).map(|m| m.as_str()).unwrap();
let suffix = captures.get(3).map(|m| m.as_str()).unwrap_or("");
let formatted_commit =
format_osc8_hyperlink(&commit_link_format.replace("{commit}", commit), commit);
format!("{prefix}{formatted_commit}{suffix}")
})
} else if let Some(repo) = config.git_config().and_then(GitConfig::get_remote_url) {
COMMIT_LINE_REGEX.replace(line, |captures: &Captures| {
format_commit_line_captures_with_osc8_commit_hyperlink(captures, &repo)
})
} else {
Cow::from(line)
}
}

@dandavison
Copy link
Owner

I'm guessing that if you set hyperlinks-commit-link-format it works in VSCode, right? It's something to do with the git remote not being identified in the vscode context?

@gczajkowskiTT
Copy link

Here is something interesting hyperlinks = true alone does not enable links by default. However, if I add a hard-coded repo specific hyperlinks-commit-link-format = "https://<gitlab.server.instance/path/to/project/-/commit/{commit}/"

Then

  1. delta attempts to add the links to git blame
  2. the links have multiple shaids?
    https://<gitlab.server.instance/path/to/project/-/commit/{commit}/someothershaid
  3. the links are still very broken in linux kitty

From the documentation:

Commit hashes link to GitHub/GitLab/Bitbucket (use hyperlinks-commit-link-format for full control).

So this won't work for our private gitlab instances

It's something to do with the git remote not being identified in the vscode context?

Not sure. If I add hyperlinks-commit-link-format to both Linux and MacOS, the links are added.However I have no clue what to add for hyperlinks-commit-link-format in a local repo.

On MacOS: git config --local --get remote.origin.url returns {host}:/path/to/clone
On Linux: git config --local --get remote.origin.url correctly returns the URI which is not a URL since it uses [email protected]:<path/project.git> scheme. And we have hundreds of projects and several gitlab private instances so I would probably have to figure out a repo URI/URL dynamically per OS

(For my reference I was looking at #613)

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

No branches or pull requests

3 participants