-
-
Notifications
You must be signed in to change notification settings - Fork 27k
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
Changes from 6 commits
61cfcec
bdabc3e
6ff17ae
eca2714
8be4f32
0d68efe
fe3bb7f
cf57f57
44ae1e2
c3dc075
e7e0392
a72073c
70b9b5b
e317052
ad7cd2c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ const path = require('path'); | |
const spawnSync = require('cross-spawn').sync; | ||
const chalk = require('chalk'); | ||
const prompt = require('react-dev-utils/prompt'); | ||
const execSync = require('child_process').execSync; | ||
const paths = require('../config/paths'); | ||
const createJestConfig = require('./utils/createJestConfig'); | ||
|
||
|
@@ -36,6 +37,31 @@ prompt( | |
process.exit(1); | ||
} | ||
|
||
// Make sure there are no dirty git status | ||
function statusSync() { | ||
try { | ||
let stdout = execSync(`git status -s`).toString(); | ||
let status = { dirty: 0, untracked: 0 }; | ||
stdout.trim().split(/\r?\n/).forEach(file => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You might want to use |
||
if (file.substr(0, 2) === '??') status.untracked++; | ||
else status.dirty++; | ||
}); | ||
return status; | ||
} catch (e) { | ||
return false; | ||
} | ||
} | ||
|
||
const status = statusSync(); | ||
if (status && status.dirty) { | ||
console.error( | ||
`Git repository has ${status.dirty} dirty ${status.dirty > 1 ? 'files' : 'file'}. ` + | ||
'We cannot continue as you would lose all the changes in that file or directory. ' + | ||
'Please push commit before and run this command again.' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this error message covers all the right bases. The grammar however is a bit confusing. The first sentence mentions that you have 1 or more dirty files, but then the second sentence only refers to a single file or directory. The third sentence isn't totally clear grammatically and it states that you need to push as well as commit in order to make the directory clean. While pushing may be ideal, it isn't the same as committing and only committing is really necessary here. What do you think of this as the error message instead? `This git repository has ${status.dirty} dirty ${status.dirty > 1 ? 'files' : 'file'}. ` +
'We cannot continue as you would lose all of your changes. ' +
'Please commit your changes with `git commit` and then run this command again.' This way, the user knows what to do to fix the problem and the message is completely clear. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My attempt at the grammar on this: `This git repository has ${status.dirty} ${status.dirty > 1 ? 'files' : 'file'} with uncommitted changes.` +
'Ejecting would cause these files to be overwritten. ' +
'Please commit your changes with `git commit` and then run this command again.' There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for those suggestions @sunjay, @taylorlapeyre. I personally liked @taylorlapeyre version. I will make an update soon. |
||
); | ||
process.exit(1); | ||
} | ||
|
||
console.log('Ejecting...'); | ||
|
||
const ownPath = paths.ownPath; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're also counting untracked files, why isn't that used in the dirty check below? If it shouldn't be used, why is it being counted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, I think untracked files should be exclude. I will make pull request on this tonight.