-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathgit-utils.ts
More file actions
30 lines (26 loc) · 749 Bytes
/
git-utils.ts
File metadata and controls
30 lines (26 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import simpleGit from 'simple-git';
import * as vscode from 'vscode';
import { Logger } from './logger';
/**
* Retrieves the staged changes from the Git repository.
*/
export async function getDiffStaged(
repo: any
): Promise<{ diff: string; error?: string }> {
try {
const rootPath =
repo?.rootUri?.fsPath || vscode.workspace.workspaceFolders?.[0].uri.fsPath;
if (!rootPath) {
throw new Error('No workspace folder found');
}
const git = simpleGit(rootPath);
const diff = await git.diff(['--staged']);
return {
diff: diff || 'No changes staged.',
error: null
};
} catch (error) {
Logger.error('Error reading Git diff:', error);
return { diff: '', error: error.message };
}
}