Skip to content

Commit 247e5c9

Browse files
mauricedbgaearon
authored andcommitted
Create git repository with initial commit (facebook#1288)
* Create git repo with initial commit * Fixe commit message * Added the git repo to the docs * Bail if we are in a mercurial repository * Removed Chore from commit mesage * Create repo after installing react and react-dom * Removed docs * Commit changes when ejecting * Update after review * git add -A instead of git add . after code review
1 parent d67a9e7 commit 247e5c9

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

packages/react-scripts/scripts/init.js

+43
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,49 @@ process.on('unhandledRejection', err => {
1717
const fs = require('fs-extra');
1818
const path = require('path');
1919
const chalk = require('chalk');
20+
const execSync = require('child_process').execSync;
2021
const spawn = require('react-dev-utils/crossSpawn');
2122
const { defaultBrowsers } = require('react-dev-utils/browsersHelper');
2223
const os = require('os');
2324

25+
function insideGitRepository() {
26+
try {
27+
execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore' });
28+
return true;
29+
} catch (e) {
30+
return false;
31+
}
32+
}
33+
34+
function insideMercurialRepository() {
35+
try {
36+
execSync('hg --cwd . root', { stdio: 'ignore' });
37+
return true;
38+
} catch (e) {
39+
return false;
40+
}
41+
}
42+
43+
function gitInit() {
44+
try {
45+
execSync('git --version', { stdio: 'ignore' });
46+
47+
if (insideGitRepository() || insideMercurialRepository()) {
48+
return false;
49+
}
50+
51+
execSync('git init', { stdio: 'ignore' });
52+
execSync('git add -A', { stdio: 'ignore' });
53+
execSync('git commit -m "Initial commit from Create React App"', {
54+
stdio: 'ignore',
55+
});
56+
57+
return true;
58+
} catch (e) {
59+
return false;
60+
}
61+
}
62+
2463
module.exports = function(
2564
appPath,
2665
appName,
@@ -134,6 +173,10 @@ module.exports = function(
134173
}
135174
}
136175

176+
if (gitInit()) {
177+
console.log('Initialized git repository');
178+
}
179+
137180
// Display the most elegant way to cd.
138181
// This needs to handle an undefined originalDirectory for
139182
// backward compatibility with old global-cli's.

tasks/e2e-kitchensink.sh

+6
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ 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+
177183
# Eject...
178184
echo yes | npm run eject
179185

tasks/e2e-simple.sh

+6
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,12 @@ verify_module_scope
261261
# Finally, let's check that everything still works after ejecting.
262262
# ******************************************************************************
263263

264+
# Commiting changes
265+
git config user.email "you@example.com"
266+
git config user.name "Your Name"
267+
git add .
268+
git commit -m "Before npm run eject"
269+
264270
# Eject...
265271
echo yes | npm run eject
266272

0 commit comments

Comments
 (0)