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 1 commit
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 @@ -21,6 +21,7 @@ const path = require('path');
const spawnSync = require('cross-spawn').sync;
const chalk = require('chalk');
const inquirer = require('inquirer');
const execSync = require('child_process').execSync;
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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious, what does this do if git is not installed or if the app is using a VCS other than git?

Copy link
Contributor

@Timer Timer May 20, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It throws an error and is caught, then returns false. 😄 We can add cases for other VCS, but git is by far the most common.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes 🤦‍♂️

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