Warn if on 'main' when moving content (#44751)
This commit is contained in:
@@ -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()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user