carlthome / vscode-git-line-blame

Display inline information of the last commit that edited the currently selected line in the editor
https://marketplace.visualstudio.com/items?itemName=carlthome.git-line-blame
GNU Affero General Public License v3.0
21 stars 5 forks source link

Blame unsaved files correctly #26

Closed dereli closed 9 months ago

dereli commented 9 months ago

Issue

If a file is changed with new lines added or removed, but unsaved, blame doesn't function properly.

Solution

Add current file content while running git blame and let git do its job.

carlthome commented 9 months ago

Great fix! Thanks! :clap:

Guess there could be some minor overhead from piping file contents to git (for large files at least) but probably worth it?

Personally, I have the habit of saving files on pretty much every keystroke (also to trigger auto-formatting, etc.), and rely on the staging area in git as the "unsaved" version, but this seems like a nice complement for those who prefer file saving as a form of "commit to disk" step, and the unsaved file alive in the editor as a form of lightweight staging step.

dereli commented 9 months ago

Thanks Carl,

Guess there could be some minor overhead from piping file contents to git (for large files at least) but probably worth it?

I tested it (well on a relatively fast computer) with a file containing more than a 10000 lines, there's no considerable slowness. But it'll be slower for sure.

On the other hand, I believe isUnsaved condition below will never be hit, since unsaved changes will always be uncommitted. Reverting the order might help, I will do it if I have time later the weekend. I think this is dependent on Git version, I never seem to get isUnsaved.


  if (isUncommitted) {
    return "Not committed yet";
  } else if (isUnsaved) {
    return "Unsaved changes";
  } else {
    return defaultMessage;
  }