1
0
mirror of synced 2026-01-05 12:07:35 -05:00

Warn if on 'main' when moving content (#44751)

This commit is contained in:
Peter Bengtsson
2023-10-20 11:52:20 -04:00
committed by GitHub
parent 93698ba31e
commit 4e9e8b5d91

View File

@@ -53,7 +53,7 @@ program
main(program.opts(), program.args)
async function main(opts, nameTuple) {
const { verbose, undo } = opts
const { verbose, undo, git } = opts
if (nameTuple.length !== 2) {
console.error(
chalk.red(`Must be exactly 2 file paths as arguments. Not ${nameTuple.length} arguments.`),
@@ -115,6 +115,14 @@ async function main(opts, nameTuple) {
}
}
const currentBranchName = getCurrentBranchName(verbose)
if (currentBranchName === 'main' && git) {
console.error(chalk.red("Cannot proceed because you're on the 'main' branch."))
console.error("This command will executed 'git mv ...' and 'git commit ...'")
console.error('Create a new dedicated branch instead, first, for this move.\n')
process.exit(2)
}
// This will exit non-zero if anything is wrong with these inputs
validateFileInputs(oldPath, newPath, isFolder)
@@ -566,3 +574,12 @@ function changeLearningTracks(filePath, oldHref, newHref) {
const newContent = oldContent.replace(regex, `- ${newHref}`)
fs.writeFileSync(filePath, newContent, 'utf-8')
}
function getCurrentBranchName(verbose = false) {
const cmd = 'git branch --show-current'
const o = execSync(cmd)
if (verbose) {
console.log(`git commit command: ${chalk.grey(cmd)}`)
}
return o.toString().trim()
}