-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchanged-files.js
35 lines (28 loc) · 1015 Bytes
/
changed-files.js
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
#!/usr/bin/env node
import { execSync } from "child_process";
export function checkGitStatus() {
const statusOutput = execSync("git status").toString().trim();
const lines = statusOutput.split("\n");
let files = [];
let isModifiedSection = false;
let isUntrackedSection = false;
lines.forEach((line) => {
if (line.startsWith("Changes not staged for commit:")) {
isModifiedSection = true;
isUntrackedSection = false;
} else if (line.startsWith("Untracked files:")) {
isModifiedSection = false;
isUntrackedSection = true;
} else if (line.trim().startsWith("(")) {
// Skip lines with git instructions
return;
} else if (isModifiedSection && line.trim().startsWith("modified:")) {
files.push(line.trim().split(":")[1].trim());
} else if (isUntrackedSection && !line.startsWith("no changes added")) {
files.push(line.trim());
}
});
// Filter out empty strings
files = files.filter((file) => file !== "");
return files;
}