Skip to content

Commit d49ffde

Browse files
authored
Fix the E2E script (facebook#3888)
* Fix the E2E script * Delete .git if committing failed
1 parent 1cf2248 commit d49ffde

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

packages/react-scripts/scripts/init.js

+21-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const spawn = require('react-dev-utils/crossSpawn');
2222
const { defaultBrowsers } = require('react-dev-utils/browsersHelper');
2323
const os = require('os');
2424

25-
function insideGitRepository() {
25+
function isInGitRepository() {
2626
try {
2727
execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore' });
2828
return true;
@@ -31,7 +31,7 @@ function insideGitRepository() {
3131
}
3232
}
3333

34-
function insideMercurialRepository() {
34+
function isInMercurialRepository() {
3535
try {
3636
execSync('hg --cwd . root', { stdio: 'ignore' });
3737
return true;
@@ -40,22 +40,36 @@ function insideMercurialRepository() {
4040
}
4141
}
4242

43-
function tryGitInit() {
43+
function tryGitInit(appPath) {
44+
let didInit = false;
4445
try {
4546
execSync('git --version', { stdio: 'ignore' });
46-
47-
if (insideGitRepository() || insideMercurialRepository()) {
47+
if (isInGitRepository() || isInMercurialRepository()) {
4848
return false;
4949
}
5050

5151
execSync('git init', { stdio: 'ignore' });
52+
didInit = true;
53+
5254
execSync('git add -A', { stdio: 'ignore' });
5355
execSync('git commit -m "Initial commit from Create React App"', {
5456
stdio: 'ignore',
5557
});
56-
5758
return true;
5859
} catch (e) {
60+
if (didInit) {
61+
// If we successfully initialized but couldn't commit,
62+
// maybe the commit author config is not set.
63+
// In the future, we might supply our own committer
64+
// like Ember CLI does, but for now, let's just
65+
// remove the Git files to avoid a half-done state.
66+
try {
67+
// unlinkSync() doesn't work on directories.
68+
fs.removeSync(path.join(appPath, '.git'));
69+
} catch (removeErr) {
70+
// Ignore.
71+
}
72+
}
5973
return false;
6074
}
6175
}
@@ -172,7 +186,7 @@ module.exports = function(
172186
}
173187
}
174188

175-
if (tryGitInit()) {
189+
if (tryGitInit(appPath)) {
176190
console.log();
177191
console.log('Initialized a git repository.');
178192
}

tasks/e2e-kitchensink.sh

-6
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,6 @@ rm .babelrc
174174
# Finally, let's check that everything still works after ejecting.
175175
# ******************************************************************************
176176

177-
# Commiting changes
178-
git config user.email "you@example.com"
179-
git config user.name "Your Name"
180-
git add .
181-
git commit -m "Before npm run eject"
182-
183177
# Eject...
184178
echo yes | npm run eject
185179

0 commit comments

Comments
 (0)