From 3458262f6673ab3cf545ff8732beee18e65b068e Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Sun, 21 Jan 2018 23:31:03 +0000 Subject: [PATCH] Fix the E2E script (#3888) * Fix the E2E script * Delete .git if committing failed --- packages/react-scripts/scripts/init.js | 28 +++++++++++++++++++------- tasks/e2e-kitchensink.sh | 6 ------ 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/packages/react-scripts/scripts/init.js b/packages/react-scripts/scripts/init.js index 3347a37f4f3..ac695d167d9 100644 --- a/packages/react-scripts/scripts/init.js +++ b/packages/react-scripts/scripts/init.js @@ -22,7 +22,7 @@ const spawn = require('react-dev-utils/crossSpawn'); const { defaultBrowsers } = require('react-dev-utils/browsersHelper'); const os = require('os'); -function insideGitRepository() { +function isInGitRepository() { try { execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore' }); return true; @@ -31,7 +31,7 @@ function insideGitRepository() { } } -function insideMercurialRepository() { +function isInMercurialRepository() { try { execSync('hg --cwd . root', { stdio: 'ignore' }); return true; @@ -40,22 +40,36 @@ function insideMercurialRepository() { } } -function tryGitInit() { +function tryGitInit(appPath) { + let didInit = false; try { execSync('git --version', { stdio: 'ignore' }); - - if (insideGitRepository() || insideMercurialRepository()) { + if (isInGitRepository() || isInMercurialRepository()) { return false; } execSync('git init', { stdio: 'ignore' }); + didInit = true; + execSync('git add -A', { stdio: 'ignore' }); execSync('git commit -m "Initial commit from Create React App"', { stdio: 'ignore', }); - return true; } catch (e) { + if (didInit) { + // If we successfully initialized but couldn't commit, + // maybe the commit author config is not set. + // In the future, we might supply our own committer + // like Ember CLI does, but for now, let's just + // remove the Git files to avoid a half-done state. + try { + // unlinkSync() doesn't work on directories. + fs.removeSync(path.join(appPath, '.git')); + } catch (removeErr) { + // Ignore. + } + } return false; } } @@ -172,7 +186,7 @@ module.exports = function( } } - if (tryGitInit()) { + if (tryGitInit(appPath)) { console.log(); console.log('Initialized a git repository.'); } diff --git a/tasks/e2e-kitchensink.sh b/tasks/e2e-kitchensink.sh index b849c367944..a1e1ccc9d42 100755 --- a/tasks/e2e-kitchensink.sh +++ b/tasks/e2e-kitchensink.sh @@ -174,12 +174,6 @@ rm .babelrc # Finally, let's check that everything still works after ejecting. # ****************************************************************************** -# Commiting changes -git config user.email "you@example.com" -git config user.name "Your Name" -git add . -git commit -m "Before npm run eject" - # Eject... echo yes | npm run eject