Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions packages/react-scripts/scripts/eject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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',
Expand All @@ -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);
}

Expand Down