Sertion / vscode-gitblame

Visual Studio Code Extension - See Git Blame info in status bar.
https://marketplace.visualstudio.com/items/waderyan.gitblame
MIT License
72 stars 31 forks source link

Blame uses committer not author #33

Closed KenCoder closed 6 years ago

KenCoder commented 6 years ago

If the committer and author are different for a commit, blame always uses committer even if you specify author.name. I wonder if this is what's behind #32

Looking at the code, I believe it is due to the following problem. When blame.ts initializes a commit object, it uses the exact same reference for emptyAuthor for both author and commit. When stream.ts reads the information, it mutates the owner object, which in this case points to both the author and the commit. I think the solution is simply to copy the object when initializing in blame.ts.

I would submit a CR but don't want to spend the time setting everything up, reproing, creating a test, etc.

Fix in blame.ts

const commitInfo = {
            author: {...emptyAuthor},
            committer: {...emptyAuthor},

Original blame.ts

const commitInfo = {
            author: emptyAuthor,
            committer: emptyAuthor,
            filename: "",
            generated: true,
            hash: HASH_NO_COMMIT_GIT,
            summary: "",
        } as IGitCommitInfo;

stream.ts - point where it is mutated

       if (keyPrefix === "author") {
            owner = commitInfo.author;
        } else if (keyPrefix === "committer") {
            owner = commitInfo.committer;
        }

        if (!owner.temporary && !keySuffix) {
            owner.name = value;
Sertion commented 6 years ago

Hey KenCoder! Thank you for the issue and investigation.

This will be fixed in the upcoming version.

Sertion commented 6 years ago

This has been solved in 2.4.2.