Skip to content

Commit ed8dec5

Browse files
committed
add a push dry run in the pre-publish hook
1 parent 03c8bc8 commit ed8dec5

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

scripts/prepublish.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,18 @@ await Promise.all([
1717
await Promise.all([
1818
(async () => {
1919
try {
20-
// `git status --porecelain` is empty when the tree is clean
21-
const {stdout: status} = await readGit('status', '--porcelain')
22-
if (status.trim() !== '') errors.push("/!\\ The git working tree is not clean")
23-
2420
const {stdout: branch} = await readGit('branch', '--show-current')
2521
if (branch !== "main\n") {
2622
errors.push(`/!\\ We are on branch ${branch.trim()}, we publish from main`)
2723

2824
}
25+
// `git status --porecelain` is empty when the tree is clean
26+
const {stdout: status} = await readGit('status', '--porcelain')
27+
if (status.trim() !== '') errors.push("/!\\ The git working tree is not clean")
28+
29+
const _ignore = await readGit('push', '--dry-run', '--porcelain')
2930
} catch({stderr, stdout}) {
30-
errors.push("/!\\ git status or git branch error:", stdout, stderr)
31+
errors.push("/!\\ git status, git branch or git push --dry-run error:", stdout, stderr)
3132
}
3233
})(),
3334
(async () => {
@@ -62,7 +63,7 @@ await Promise.all([
6263

6364

6465
if (errors.length !== 0) {
65-
console.error('\n' + errors.join('\n\n') + '\n')
66+
console.error('\n' + errors.filter(x=>x!=='').join('\n\n') + '\n')
6667
process.exit(1)
6768
}
6869

0 commit comments

Comments
 (0)