Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Keep the ignored files during the upgrade process #17393

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion react-native-git-upgrade/cliEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,28 @@ function configureGitEnv(tmpDir) {
process.env.GIT_WORK_TREE = '.';
}

function copyCurrentGitIgnoreFile(tmpDir) {
/*
* The user may have added new files or directories in the .gitignore file.
* We need to keep those files ignored during the process, otherwise they
* will be deleted.
* See https://github.com/facebook/react-native/issues/12237
*/
try {
const gitignorePath = path.resolve(process.cwd(), '.gitignore');
const repoExcludePath = path.resolve(tmpDir, process.env.GIT_DIR, 'info/exclude');
const content = fs.readFileSync(gitignorePath, 'utf8');
fs.appendFileSync(repoExcludePath, content);
} catch (err) {
if (err.code === 'ENOENT') {
log.info('No .gitignore file found, this step is a no-op');
return;
}

throw err;
}
}

function generateTemplates(generatorDir, appName, verbose) {
try {
const yeomanGeneratorEntryPoint = path.resolve(generatorDir, 'index.js');
Expand Down Expand Up @@ -277,9 +299,12 @@ async function run(requestedVersion, cliArgs) {
log.info('Configure Git environment');
configureGitEnv(tmpDir);

log.info('Init Git repository');
log.info('Init temporary Git repository');
await exec('git init', verbose);

log.info('Save current .gitignore file');
copyCurrentGitIgnoreFile(tmpDir);

log.info('Add all files to commit');
await exec('git add .', verbose);

Expand Down