Skip to content

Commit

Permalink
Keep the ignored files during the upgrade process
Browse files Browse the repository at this point in the history
When the user adds new files to the .gitignore file,
those files are deleted during the upgrade process
because it starts by creating a fresh .gitignore file
without user's modification. This commit adds a step
to move the excluded file at the repository level so
that they are kept ignored during the upgrade process.
  • Loading branch information
ncuillery committed Jan 31, 2018
1 parent b1cdb7d commit e2bf90e
Showing 1 changed file with 26 additions and 1 deletion.
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');
await copyCurrentGitIgnoreFile(tmpDir);

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

Expand Down

0 comments on commit e2bf90e

Please sign in to comment.