简体   繁体   English

SimpleGit 库不适用于 vscode 扩展

[英]SimpleGit library not working with vscode extension

I'm trying to get SimpleGit to work in my vscode extension.我正在尝试让SimpleGit在我的 vscode 扩展中工作。 To make sure I'm using it properly I created this typescript file为了确保我正确使用它,我创建了这个 typescript 文件

import simpleGit, { SimpleGit, CleanOptions } from 'simple-git';

const git: SimpleGit = simpleGit().clean(CleanOptions.FORCE);

async function main() {
    try {
        const status = await git.status();
        console.log("STATUS", status);
    } catch (e) {
        console.log("ERROR", e);
    }
}

if (require.main === module) {
    main();
}

and was able to use the library successfully with no issues.并且能够毫无问题地成功使用该库。 When I try and execute the same call in my vscode extension I get in the debug console ERROR Error: fatal: not a git repository (or any of the parent directories): .git当我尝试在我的 vscode 扩展中执行相同的调用时,我进入调试控制台ERROR Error: fatal: not a git repository (or any of the parent directories): .git

I'm also seeing this as well in debug console as well.我也在调试控制台中也看到了这一点。 Might be related.可能有关系。

在此处输入图像描述

How can I get the same call to work in vscode extension?如何在 vscode 扩展中获得相同的调用? What am I doing wrong?我究竟做错了什么? I appreciate any help!感谢您的帮助!

import * as vscode from 'vscode';
import simpleGit, { SimpleGit, CleanOptions } from 'simple-git';

export function activate(context: vscode.ExtensionContext) {

    let disposable = vscode.commands.registerCommand('my-app.createUrl', async (uri: vscode.Uri) => {
        const git: SimpleGit = simpleGit().clean(CleanOptions.FORCE);
        try {
            const status = await git.status();
            console.log("STATUS", status);
        } catch (e) {
            console.log("ERROR", e);
        }
    });

    context.subscriptions.push(disposable);
}

export function deactivate() { }

You have to tell it where the repo is你必须告诉它 repo 在哪里

const git = simpleGit(__dirname);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM