1
0
mirror of synced 2025-12-19 18:10:59 -05:00
Files
docs/script/prevent-pushes-to-main.js
2023-07-11 11:44:52 +00:00

27 lines
778 B
JavaScript

#!/usr/bin/env node
// [start-readme]
// This script is intended to be used as a git "prepush" hook.
// If the current branch is main, it will exit unsuccessfully and prevent the push.
// [end-readme]
import { execSync } from 'child_process'
const productionBranch = 'main'
const currentBranch = execSync('git symbolic-ref --short HEAD', { encoding: 'utf8' }).trim()
if (currentBranch === productionBranch) {
console.error('')
console.error(
`🤚 Whoa! Pushing to the ${productionBranch} branch has been disabled to prevent accidental deployments to production.`,
)
console.error('')
console.error(
"If you're aware of the risks and really want to push to this branch, add --no-verify to bypass this check.",
)
console.error('')
process.exit(1)
}