Unverified Commit b3527d77 authored by Dan Abramov's avatar Dan Abramov Committed by GitHub
Browse files

Fix git init race condition (#3877)

parent ab2e0f87
Showing with 19 additions and 19 deletions
+19 -19
...@@ -40,7 +40,7 @@ function insideMercurialRepository() { ...@@ -40,7 +40,7 @@ function insideMercurialRepository() {
} }
} }
function gitInit() { function tryGitInit() {
try { try {
execSync('git --version', { stdio: 'ignore' }); execSync('git --version', { stdio: 'ignore' });
...@@ -114,23 +114,22 @@ module.exports = function( ...@@ -114,23 +114,22 @@ module.exports = function(
// Rename gitignore after the fact to prevent npm from renaming it to .npmignore // Rename gitignore after the fact to prevent npm from renaming it to .npmignore
// See: https://github.com/npm/npm/issues/1862 // See: https://github.com/npm/npm/issues/1862
fs.move( try {
path.join(appPath, 'gitignore'), fs.moveSync(
path.join(appPath, '.gitignore'), path.join(appPath, 'gitignore'),
[], path.join(appPath, '.gitignore'),
err => { []
if (err) { );
// Append if there's already a `.gitignore` file there } catch (err) {
if (err.code === 'EEXIST') { // Append if there's already a `.gitignore` file there
const data = fs.readFileSync(path.join(appPath, 'gitignore')); if (err.code === 'EEXIST') {
fs.appendFileSync(path.join(appPath, '.gitignore'), data); const data = fs.readFileSync(path.join(appPath, 'gitignore'));
fs.unlinkSync(path.join(appPath, 'gitignore')); fs.appendFileSync(path.join(appPath, '.gitignore'), data);
} else { fs.unlinkSync(path.join(appPath, 'gitignore'));
throw err; } else {
} throw err;
}
} }
); }
let command; let command;
let args; let args;
...@@ -173,8 +172,9 @@ module.exports = function( ...@@ -173,8 +172,9 @@ module.exports = function(
} }
} }
if (gitInit()) { if (tryGitInit()) {
console.log('Initialized git repository'); console.log();
console.log('Initialized a git repository.');
} }
// Display the most elegant way to cd. // Display the most elegant way to cd.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment