1

I'm trying to get SimpleGit to work in my vscode extension. To make sure I'm using it properly I created this typescript file

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

I'm also seeing this as well in debug console as well. Might be related.

enter image description here

How can I get the same call to work in vscode extension? 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() { }
steveukx
  • 4,370
  • 19
  • 27
user6680
  • 79
  • 6
  • 34
  • 78
  • looks like you have to tell it where the repo is `const git = simpleGit(__dirname);` – rioV8 Apr 14 '22 at 16:09
  • That was the issue. Thanks! If you wanna make it an answer, I'll mark it with check mark and give you bounty. – user6680 Apr 15 '22 at 00:34

1 Answers1

1

You have to tell it where the repo is

const git = simpleGit(__dirname);
rioV8
  • 24,506
  • 3
  • 32
  • 49