Skip to content

Commit

Permalink
Ejecting should ensure you have clean git status (#2221)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
milocosmopolitan authored and gaearon committed May 20, 2017
1 parent ba0d0da commit a257e7d
Showing 1 changed file with 25 additions and 0 deletions.
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

0 comments on commit a257e7d

Please sign in to comment.