mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-04-28 09:25:42 +08:00
Ejecting should ensure you have clean git status (#2221)
* Ejecting should ensure you have clean git status * Rename function * Style * Minor changes - extract function - exclude error output for missing git - more descriptive error message - no need to mutate answer - fix answering "no" to return 0 exit code
This commit is contained in:
25
packages/react-scripts/scripts/eject.js
vendored
25
packages/react-scripts/scripts/eject.js
vendored
@@ -18,6 +18,7 @@ process.on('unhandledRejection', err => {
|
||||
|
||||
const fs = require('fs-extra');
|
||||
const path = require('path');
|
||||
const execSync = require('child_process').execSync;
|
||||
const spawnSync = require('cross-spawn').sync;
|
||||
const chalk = require('chalk');
|
||||
const inquirer = require('inquirer');
|
||||
@@ -27,6 +28,17 @@ const createJestConfig = require('./utils/createJestConfig');
|
||||
const green = chalk.green;
|
||||
const cyan = chalk.cyan;
|
||||
|
||||
function getGitStatus() {
|
||||
try {
|
||||
let stdout = execSync(`git status --porcelain`, {
|
||||
stdio: ['pipe', 'pipe', 'ignore'],
|
||||
}).toString();
|
||||
return stdout.trim();
|
||||
} catch (e) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
inquirer
|
||||
.prompt({
|
||||
type: 'confirm',
|
||||
@@ -37,6 +49,19 @@ inquirer
|
||||
.then(answer => {
|
||||
if (!answer.shouldEject) {
|
||||
console.log(cyan('Close one! Eject aborted.'));
|
||||
return;
|
||||
}
|
||||
|
||||
const gitStatus = getGitStatus();
|
||||
if (gitStatus) {
|
||||
console.error(
|
||||
chalk.red(
|
||||
`This git repository has untracked files or uncommitted changes:\n\n` +
|
||||
gitStatus.split('\n').map(line => ' ' + line) +
|
||||
'\n\n' +
|
||||
'Remove untracked files, stash or commit any changes, and try again.'
|
||||
)
|
||||
);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user