Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

Commit 3c3f519

Browse files
MasonRhodesDevKnisterPeter
authored andcommitted
fix: add cwd for git path context
Windows was running git from vscode dir instead of workspace by default. fixes #429
1 parent 9522d47 commit 3c3f519

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

src/extension.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,29 @@ interface CzConfig {
7575

7676
let gitRoot: string | undefined = undefined;
7777
async function findLookupPath(): Promise<string | undefined> {
78+
let ws = '';
79+
if (!vscode.workspace.workspaceFolders) {
80+
return undefined;
81+
} else {
82+
ws = vscode.workspace.workspaceFolders[0].uri.fsPath;
83+
}
84+
7885
if (getConfiguration().useGitRoot && gitRoot === undefined) {
7986
gitRoot = await new Promise<string>((resolve, reject) =>
80-
exec('git rev-parse --show-toplevel', (err, stdout, stderr) => {
81-
if (err) {
82-
reject({ err, stderr });
83-
} else if (stdout) {
84-
channel.appendLine(`Found git root at: ${stdout}`);
85-
resolve(stdout.trim());
86-
} else {
87-
reject({ err: 'Unable to find git root' });
87+
exec(
88+
'git rev-parse --show-toplevel',
89+
{ cwd: ws },
90+
(err, stdout, stderr) => {
91+
if (err) {
92+
reject({ err, stderr });
93+
} else if (stdout) {
94+
channel.appendLine(`Found git root at: ${stdout}`);
95+
resolve(stdout.trim());
96+
} else {
97+
reject({ err: 'Unable to find git root' });
98+
}
8899
}
89-
})
100+
)
90101
).catch((e) => {
91102
channel.appendLine(e.err.toString());
92103
if (e.stderr) {
@@ -98,10 +109,8 @@ async function findLookupPath(): Promise<string | undefined> {
98109

99110
if (gitRoot) {
100111
return gitRoot;
101-
} else if (!vscode.workspace.workspaceFolders) {
102-
return undefined;
103112
} else {
104-
return vscode.workspace.workspaceFolders[0].uri.fsPath;
113+
return ws;
105114
}
106115
}
107116

0 commit comments

Comments
 (0)