Skip to content

Commit c3f34dc

Browse files
authored
Add more messages to prettier prepush to help diagnose intermittent problems (#2909)
1 parent 294bed4 commit c3f34dc

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

tools/gitHooks/license.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const { resolve } = require('path');
1919
const simpleGit = require('simple-git/promise');
2020
const fs = require('mz/fs');
2121
const ora = require('ora');
22+
const chalk = require('chalk');
2223

2324
const root = resolve(__dirname, '../..');
2425
const git = simpleGit(root);
@@ -116,16 +117,24 @@ async function doLicenseCommit(changedFiles) {
116117

117118
const hasDiff = await git.diff();
118119

119-
if (!hasDiff) return;
120+
if (!hasDiff) {
121+
console.log(
122+
chalk`\n{red License pass caused no changes.} Skipping commit.\n`
123+
);
124+
return;
125+
}
120126

121127
const gitSpinner = ora(' Creating automated license commit').start();
122128
await git.add('.');
123129

124-
await git.commit('[AUTOMATED]: License Headers');
130+
const commit = await git.commit('[AUTOMATED]: License Headers');
125131

126132
gitSpinner.stopAndPersist({
127133
symbol: '✅'
128134
});
135+
console.log(
136+
chalk`{green Commited ${commit.commit} to branch ${commit.branch}}`
137+
);
129138
}
130139

131140
module.exports = {

tools/gitHooks/prettier.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ async function doPrettierCommit(changedFiles) {
6666

6767
// Only run on .js or .ts files.
6868
const targetFiles = changedFiles.filter(line => line.match(/(js|ts)$/));
69-
if (targetFiles.length === 0) return;
69+
if (targetFiles.length === 0) {
70+
console.log('No files changed.');
71+
}
7072

7173
const stylingSpinner = ora(
7274
` Formatting ${targetFiles.length} files with prettier`
@@ -88,15 +90,23 @@ async function doPrettierCommit(changedFiles) {
8890

8991
const hasDiff = await git.diff();
9092

91-
if (!hasDiff) return;
93+
if (!hasDiff) {
94+
console.log(
95+
chalk`\n{red Prettier formatting caused no changes.} Skipping commit.\n`
96+
);
97+
return;
98+
}
9299

93100
const gitSpinner = ora(' Creating automated style commit').start();
94101
await git.add(targetFiles);
95102

96-
await git.commit('[AUTOMATED]: Prettier Code Styling');
103+
const commit = await git.commit('[AUTOMATED]: Prettier Code Styling');
97104
gitSpinner.stopAndPersist({
98105
symbol: '✅'
99106
});
107+
console.log(
108+
chalk`{green Commited ${commit.commit} to branch ${commit.branch}}`
109+
);
100110
}
101111

102112
module.exports = {

0 commit comments

Comments
 (0)