-
Notifications
You must be signed in to change notification settings - Fork 10
/
check-pristine-state
executable file
·49 lines (38 loc) · 1.06 KB
/
check-pristine-state
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
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env node
const { promisify } = require('util');
const { exec } = require('child_process');
const execAsync = promisify(exec);
const command = 'git status --porcelain | awk \'{print $2}\'';
const [...filesToIgnore] = process.argv;
const exists = item => !!item;
const isNotInList = list => item => {
const filtered = list.filter((pathToIgnore) => item.endsWith(pathToIgnore));
return filtered.length === 0;
};
const init = async () => {
const { stdout } = await execAsync(command, {
cwd: process.cwd(),
});
const changedFiles = stdout
.trim()
.split('\n')
.filter(isNotInList(filesToIgnore))
.filter(exists);
if (changedFiles.length) {
console.log(
`😰 Git shows some files have been changed (ignoring ${filesToIgnore.join(
', ',
)}). Changed files: ${changedFiles.join(', ')}`,
);
try {
const diff = await execAsync('git diff --word-diff', {
cwd: process.cwd(),
});
console.log(diff.stdout);
} catch (error) {
// continue
}
process.exit(1);
}
};
init();