ember-cli-update: Deletes git ignored files

ember update deletes .env file from the project’s root. This file is not checked into git repo and ignored by .gitignore.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 9
  • Comments: 33 (9 by maintainers)

Most upvoted comments

Still happening. Just lost my .env file, IDE local history and everything. Really frustrating. Please, add a warning to the README while this is not fixed.

@kellyselden I’ve reproduced the issue in my PC. The problem actually occurs at git-diff-apply.

Steps to reproduce:

  1. Create an ember 2.16 project.
  2. Add .env file and add it to .gitignore.
  3. ember install ember-cli-update
  4. commit.
  5. run ember update.
  6. .env file will be missing.

What happens:

  1. git checkout --orphan in git-diff-apply makes a git-init like situation where all the files and the directories in current directory become new files and are put in the git index tree.
  2. Then git reset --hard deletes all the files except the ignored files i.e. .git, node_modules and .env. These remaining files become untracked. At this point there’s no .gitignore file in the current working directory.
  3. Then the ember blueprint files are copied from the tmp directory. Now we have a .gitignore file from the ember blueprint. This file doesn’t have .env in its ignored list.
  4. Then the change is committed with git add -A.
  5. After applying diff, we checkout to the master branch and .env file is now missing.

During the investigation, I created a function like below and called it at various stages of execution:

  function checkEnvFile() {
    if (fs.existsSync(root + '/.env')) {
      console.log('.env file is still there');
    } else {
      console.log('.env file is missing');
    }
  }

.env actually gets missing from the moment we checkout back to the master branch.

Thank y’all for confirming.

Great job @kellyselden!

Closing 😅…

Just ran ember-cli-update v0.27.3 in 2 separate repos where .env.deploy.production usually is deleted. Looks like they are untouched now 👍

This happened again… and this time I didn’t backup because it was fixed 😕

In the interest of preventing data loss for additional parties, would it perhaps be best to pull the tool’s recommendation from the blog until this is resolved?

This utility will help you to ~update your app or add-on to the latest Ember CLI version~ [blow away your dev environment].

https://www.emberjs.com/blog/2018/10/15/ember-3-5-released.html @MelSumner @jenweber @runspired

@broerse The bug is probably in https://github.com/kellyselden/git-diff-apply, so a failing test case in that test suite would be perfect.

Wow. That’s a great write-up. I’m pretty sure I (or someone else) can make a failing test out of that.