summaryrefslogtreecommitdiffstats
path: root/src/GitConfig.ts
blob: 0b6f7562e4a10a7b671feb4a700967b3a1ecd0ef (plain)
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
31
32
33
34
35
36
37
import simpleGit, { ConfigValues, SimpleGit } from "simple-git";
import { workspace } from "vscode";

export default class GitConfig {
    private gitConfig: ConfigValues;

    public constructor() {
        let git: SimpleGit;
        try {
            git = simpleGit(workspace.workspaceFolders?.[0].uri.fsPath);
        } catch (error) {
            git = simpleGit();
        }

        git.listConfig().then((result) => {
            this.gitConfig = result.all;
        });
    }

    /** git config --get user.name */
    get UserName(): string {
        try {
            return this.gitConfig["user.name"].toString();
        } catch (error) {
            return "";
        }
    }

    /** git config --get user.email */
    get UserEmail(): string {
        try {
            return this.gitConfig["user.email"].toString();
        } catch (error) {
            return "";
        }
    }
}