mk12 / vscode-better-git-line-blame

VS Code extension that decorates lines with git blame information.
https://marketplace.visualstudio.com/items?itemName=mk12.better-git-line-blame
MIT License
7 stars 2 forks source link

Blame not working on Windows due to different path separator #2

Open pedrosousa opened 3 months ago

pedrosousa commented 3 months ago

There's some issue around path separators that causes the extension not to work properly in VS Code running on Windows. The path separator depends on the OS – on Windows it must be \ (backslash).

Example log of when the blame operation fails:

2024-04-08 11:59:36.338 [info] git API initialized with 1 repo(s)
2024-04-08 11:59:36.339 [info] adding git repo: c:\repo
2024-04-08 11:59:36.339 [info] blamed 0 initial file(s)
2024-04-08 11:59:41.426 [info] loading blame: c:\repo\src\file.txt
2024-04-08 11:59:41.426 [info] ERROR: path c:\repo\src\file.txt does not start with c:\repo/
2024-04-08 12:05:09.587 [info] loading blame: c:\repo\src\some_other_file.txt
2024-04-08 12:05:09.587 [info] ERROR: path c:\repo\src\some_other_file.txt does not start with c:\repo/
mk12 commented 3 months ago

Ah yes i haven’t tested on Windows. I’ll look into this today, should be easy to fix.

mk12 commented 3 months ago

@pedrosousa I published 0.2.3, let me know if that fixes it.

pedrosousa commented 2 months ago

Hi @mk12 Thank you for the quick turnaround.

Most commands work now! 🎉

The only thing still broken (apparently) is the Show Diff command. I get this error (changed the paths and the commit hash, but kept all the slashes as in the original message):

The editor could not be opened due to an unexpected error: 
Unable to resolve filesystem provider with relative file path 
'git:c:\gitrepos\repo\folder/folder2/file.md?{"ref":"617bd3da26cb4bac839a135781f483bb~","path":"c:\\gitrepos\\repo\\folder/folder2/file.md"}'
mk12 commented 2 months ago

@pedrosousa Ah I see what I missed. Let me know if 0.2.4 fixed it 🤞

pedrosousa commented 2 months ago

There's some progress (slashes are consistent), but I still get an error:

The editor could not be opened due to an unexpected error: 
Unable to resolve filesystem provider with relative file path 
'git:c:\gitrepos\repo\folder\folder2\file.md?{"ref":"617bd3da26cb4bac839a135781f483bb~","path":"c:\\gitrepos\\repo\\folder\\folder2\\file.md"}'

Is the git: prefix expected in the relative file path? I'm asking because I have no clue...

mk12 commented 2 months ago

Yes, git: is the URI scheme VS Code uses to show files from git. The problem is I'm not sure how it's formatted on Windows — it might be backslashes in the main path but forward slashes in the "path" JSON field, for example. I've created a debug-windows branch with a modified version of the extension. Could you try following these steps?

  1. Clone the repo.
    git clone https://github.com/mk12/vscode-better-git-line-blame
    cd vscode-better-git-line-blame
    git checkout debug-windows
  2. Uninstall the extension in VS Code.
  3. Install the modified extension. If you don't have the code CLI, you can also go in the Extensions pane, click the three dots, click "Install from VSIX...", and choose that file.
    code --install-extension better-git-line-blame-DEBUG-WINDOWS.vsix --force
  4. Reload VS Code.
  5. Open some project.
  6. In the Source Control pane, click on a file with changes (make a change first if there aren't any). It should open a split view with the before and after.
  7. Click in the left editor, and run the "Show Diff" command.
  8. Click in the right editor, and run the "Show Diff" command.
  9. Copy the logs it produces and paste them here. (It should say "NOTE: logging debug info for windows instead of showing diff" and then a URI, twice.)
pedrosousa commented 2 months ago

Quick update: I couldn't find the time to try this just yet, but I plan to do so.

pedrosousa commented 2 months ago

Here are the logs:

2024-04-26 12:08:33.409 [info] git API initialized with 1 repo(s)
2024-04-26 12:08:33.409 [info] adding git repo: c:\code\repo
2024-04-26 12:08:33.410 [info] blamed 0 initial file(s)
2024-04-26 12:08:41.345 [info] loading blame: c:\code\repo\main\app\views\order\edit.tpl
2024-04-26 12:10:04.950 [info] NOTE: logging debug info for windows instead of showing diff
2024-04-26 12:10:04.950 [info] active editor URI: file:///c%3A/code/repo/main/app/views/order/edit.tpl
2024-04-26 12:10:13.679 [info] NOTE: logging debug info for windows instead of showing diff
2024-04-26 12:10:13.681 [info] active editor URI: file:///c%3A/code/repo/main/app/views/order/edit.tpl

Since I mostly use the inline diff view instead of the split view (with left and right editors), I also checked the logs for this particular layout -- I can confirm that the active editor URI was the same as above.

Let me know if you need any additional testing from my side.

mk12 commented 2 months ago

Thanks! Hmm, I was hoping it would give the special git URI, but it's not.

I just pushed a new change to the debug-windows branch. Can you repeat steps 1-5 above (not 6-9) and then try using "Show Diff" command? If it works, my theory was right and I'll publish the change. If not, let me know if there's any logs.

gpunktschmitz commented 4 days ago

I just tried reproducing the steps but could not find the logs ... Anyways I tried show diff on the debug-windows branch and the behaviour is the same:

The editor could not be opened due to an unexpected error: Unable to resolve filesystem provider with relative file path 'git:d:\git\vscode-better-git-line-blame\TODO.md?{"ref":"968a77c4a152c485e7df8cdba6672eede2fb0b5f~","path":"d:\\git\\vscode-better-git-line-blame\\TODO.md"}'

mk12 commented 3 hours ago

Unfortunately I don't think me trying to fix it by trial and error like this is going to work, not having access to a Windows machine myself. It's too bad the VS Code git URL format isn't documented. I'm going to need a contributor on Windows to figure out the correct format and make a pull request.