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

Git command not found #67

Closed MarcMenghin closed 4 years ago

MarcMenghin commented 4 years ago

Git command will not be found/usable if not on path (?). VS Code already has a setting "git.path" which is set but not used by git blame it seems.

So Git works as expected in VS Code, Git Blame reports an error that git can not be executed.

[ 08:45:49 | command ] git rev-parse --show-toplevel
[ 08:45:49 | critical ] Error: spawn git ENOENT
[ 08:45:49 | info ] Will not try to blame file "c:\Users\marc.....html" as it is outside of the current workspace
[ 08:45:53 | info ] Will not try to blame file "extension-output-#13" as it is outside of the current workspace

Note: File is not outside of Workspace.

Sertion commented 4 years ago

Hello Marc!

Thank you for the issue.

Right now we use a crude implementation of the vscode.git extension api to get the git path. If we can't get it from that built in extension we default to attempting git in the path.

Sometimes it can take a while for vscode.git to get activated. Perhaps this is what you are experiencing? Does it start working after a short while (10-15 seconds)?

MarcMenghin commented 4 years ago

Git extension works as expected where I can push/pull/commit. If I open a file vs code reports the git blame error.

So, it does not start to work at any later point in time. It does work fine as soon as I put git on the path.

Furthermore, I am on the newest version of VS Code and its extensions. (just today updated to 1.39.0 with same problem)

MarcMenghin commented 4 years ago

Also, other Git related extensions (e.g. Git Graph, Git History) work fine as well.

MarcMenghin commented 4 years ago

Did check the code for Git Graph (which searches a lot for git exe, not ideal) and Git History which uses this:

this.gitExtension = extensions.getExtension('vscode.git');
this.gitApi = this.gitExtension!.exports.getAPI(1);
this.gitExecutablePath = this.gitApi.git.path;

https://github.com/DonJayamanne/gitHistoryVSCode/blob/a0cf14a13539f17f93c8ec99896cb9ecd3c55133/src/adapter/exec/gitCommandExec.ts

which looks closer to the example you mentioned. So, maybe that missing .getAPI(1) is to blame?

Sertion commented 4 years ago

Thank you for the research and quick responses!

Last time I tried to implement the getAPI function it had some issues. I can't remember exactly what but in the experiments I did yesterday it looks like it is working now. I will change getGitCommand to the following in the next version:

export async function getGitCommand(): Promise<string> {
    const vscodeGit = extensions.getExtension<GitExtension>(
        "vscode.git",
    );

    if (vscodeGit && vscodeGit.exports.enabled) {
        const api = vscodeGit.exports.getAPI(1);
        if (api.state === "initialized") {
            return api.git.path;
        } else {
            return new Promise((resolve): void => {
                api.onDidChangeState((newState): void => {
                    if (newState === "initialized") {
                        resolve(api.git.path);
                    }
                });
            });
        }
    }

    return GIT_COMMAND_IN_PATH;
}
Sertion commented 4 years ago

A fix for this was uploaded to the marketplace just now. It should be available in a few hours to a day.