Skip to content

Create git repository with initial commit #1288

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 11 commits into from
Jan 19, 2018
43 changes: 43 additions & 0 deletions packages/react-scripts/scripts/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,49 @@ process.on('unhandledRejection', err => {
const fs = require('fs-extra');
const path = require('path');
const chalk = require('chalk');
const execSync = require('child_process').execSync;
const spawn = require('react-dev-utils/crossSpawn');
const { defaultBrowsers } = require('react-dev-utils/browsersHelper');
const os = require('os');

function insideGitRepository() {
try {
execSync('git rev-parse --is-inside-work-tree', { stdio: 'ignore' });
return true;
} catch (e) {
return false;
}
}

function insideMercurialRepository() {
try {
execSync('hg --cwd . root', { stdio: 'ignore' });
return true;
} catch (e) {
return false;
}
}

function gitInit() {
try {
execSync('git --version', { stdio: 'ignore' });

if (insideGitRepository() || insideMercurialRepository()) {
return false;
}

execSync('git init', { stdio: 'ignore' });
execSync('git add -A', { stdio: 'ignore' });
execSync('git commit -m "Initial commit from Create React App"', {
stdio: 'ignore',
});

return true;
} catch (e) {
return false;
}
}

module.exports = function(
appPath,
appName,
Expand Down Expand Up @@ -134,6 +173,10 @@ module.exports = function(
}
}

if (gitInit()) {
console.log('Initialized git repository');
}

// Display the most elegant way to cd.
// This needs to handle an undefined originalDirectory for
// backward compatibility with old global-cli's.
Expand Down
6 changes: 6 additions & 0 deletions tasks/e2e-kitchensink.sh
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ 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

Expand Down
6 changes: 6 additions & 0 deletions tasks/e2e-simple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,12 @@ verify_module_scope
# 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

Expand Down