-
-
Notifications
You must be signed in to change notification settings - Fork 177
Expand file tree
/
Copy pathbuildGitInfo.mjs
More file actions
37 lines (33 loc) · 934 Bytes
/
buildGitInfo.mjs
File metadata and controls
37 lines (33 loc) · 934 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
31
32
33
34
35
36
37
import { execSync } from "child_process";
/**
* Gets git information for the current repository.
* Returns null for each field if git is not available or if there's an error.
* This should only be called during development builds.
*/
export function getGitInfo() {
try {
const branch = execSync("git rev-parse --abbrev-ref HEAD", {
encoding: "utf8",
}).trim();
const commitHash = execSync("git rev-parse --short HEAD", {
encoding: "utf8",
}).trim();
// Check for uncommitted changes (both staged and unstaged)
const statusOutput = execSync("git status --porcelain", {
encoding: "utf8",
}).trim();
const hasUncommittedChanges = statusOutput.length > 0;
return {
branch,
commitHash,
hasUncommittedChanges,
};
} catch (error) {
console.warn("Could not retrieve git information:", error.message);
return {
branch: null,
commitHash: null,
hasUncommittedChanges: null,
};
}
}