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 #2090

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
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
8 changes: 0 additions & 8 deletions packages/react-scripts/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,6 @@ function build(previousFileSizes) {
process.exit(1);
}

if (process.env.CI && stats.compilation.warnings.length) {
printErrors(
'Failed to compile. When process.env.CI = true, warnings are treated as failures. Most CI servers set this automatically.',
stats.compilation.warnings
);
process.exit(1);
}

console.log(chalk.green('Compiled successfully.'));
console.log();

Expand Down
25 changes: 25 additions & 0 deletions packages/react-scripts/scripts/eject.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const fs = require('fs-extra');
const path = require('path');
const spawnSync = require('cross-spawn').sync;
const chalk = require('chalk');
const execSync = require('child_process').execSync;
const inquirer = require('inquirer');
const paths = require('../config/paths');
const createJestConfig = require('./utils/createJestConfig');
Expand All @@ -35,6 +36,30 @@ inquirer
default: false,
})
.then(answer => {
// Make sure there are no dirty git status
function statusSync() {
try {
let stdout = execSync(`git status --porcelain`).toString();
let status = stdout
.trim()
.split(/\r?\n/)
.filter(file => file.substr(0, 2) === '??').length;
return status;
} catch (e) {
return false;
}
}

const dirtyStatus = statusSync();
if (dirtyStatus) {
console.error(
`This git repository has ${dirtyStatus} ${dirtyStatus > 1 ? 'files' : 'file'} with uncommitted changes.\n` +
'Ejecting would cause these files to be overwritten. \n' +
'Please commit your changes with `git commit` and then run this command again.'
);
answer.shouldEject = false;
}

if (!answer.shouldEject) {
console.log(cyan('Close one! Eject aborted.'));
process.exit(1);
Expand Down