Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ejecting should ensure you have clean git status #2221

Merged
merged 4 commits into from
May 20, 2017
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