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

Symfony.lock changes during composer install #379

Closed
stlrnz opened this issue Jul 10, 2018 · 10 comments
Closed

Symfony.lock changes during composer install #379

stlrnz opened this issue Jul 10, 2018 · 10 comments

Comments

@stlrnz
Copy link
Contributor

stlrnz commented Jul 10, 2018

I discovered a strange behaviour when deploying Symfony Flex applications on Windows using Git and Composer. Somehow the line endings in symfony.lock are changing during composer install. Maybe someone can give me a hint what I'm doing wrong or what I can do better.

The Environment:

  • Windows based development machine
  • Windows based production sever
  • Git configured with core.autocrlf=true on both machines

Steps to reproduce:

  1. Create a new project on dev
    composer create-project symfony/skeleton demo
    symfony.lock is created using LF charater as line endings ✔️

  2. Add everything to Git
    cd demo
    git init
    git add -A

  3. A warning is displayed but symfony.lock still has LF line endings in working copy ✔️

warning: LF will be replaced by CRLF in symfony.lock.
The file will have its original line endings in your working directory.

  1. Commit & Push
    git commit -m "init"
    git remote add origin https://...
    git push -u origin master

  2. Clone project on prod machine
    git clone https://... demo
    symfony.lock now has CRLF line endings (because of core.autocrlf=true) ✔️

  3. Check status
    cd demo
    git status

On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working tree clean

  1. Install project
    composer install
    symfony.lock now has LF line endings ❓

  2. check status again
    git status

On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add ..." to update what will be committed)
(use "git checkout -- ..." to discard changes in working directory)

    modified:   symfony.lock

no changes added to commit (use "git add" and/or "git commit -a")

So my question is why is symfony.lock updated during composer install? Is that an expected behaviour? I thougth it should be read-only during install just like composer.lock?

Everytime I update my project on production I will have to revert the changes to symfony.lock before I can do a git pull. Thats not very intuitive.

@Kris2x
Copy link

Kris2x commented Jul 13, 2018

I noticed the same problem. This is normal?

@Solthun
Copy link

Solthun commented Jan 16, 2019

Issue source is line endings in different OS, so run git config --global core.autocrlf false && git add --all (https://stackoverflow.com/a/49324186/2591726)

@stlrnz
Copy link
Contributor Author

stlrnz commented Feb 11, 2019

Im sure this is a proper workaround.
But the questions stays the same: Why is symfony.lock updated during composer install? I thought this should be a read only operation.

@fabpot
Copy link
Member

fabpot commented Feb 11, 2019

symfony.lock must NOT be updated during composer install. If you have an "old" project, first upgrade to the latest version of Flex, and then run composer update first to update the symfony.lock file. Then, it should not update anymore on composer install. If it does, there is a bug somewhere.

@stlrnz
Copy link
Contributor Author

stlrnz commented Feb 11, 2019

Thank you for your feedback, @fabpot.
I've tested the scenario again. I set up a new project like described above using Flex 1.1.8.
The result is still the same: During composer install the symfony.lock file is generated again. The content stays the same but the line endings are changing to LF.

@stlrnz
Copy link
Contributor Author

stlrnz commented Feb 22, 2019

Nice Flex 1.2 update, @fabpot!
However, I've tested this issue again with a brand new project using flex 1.2.0. The behaviour ist still the same.
Any chance to solve this problem?

@nicolas-grekas
Copy link
Member

Would you mind having a look? The code is also yours to debug ;)

@stlrnz
Copy link
Contributor Author

stlrnz commented Feb 22, 2019

Sure.
From what I found out, it's because Flex does the same on composer install like on composer update:

$this->update($event);

On update all (new?) recipes are fetched. If there are no recipes (which is the case for composer install), the Lockfile will be written:

$this->lock->write();

(Otherwise the Lockfile will be written, too. But that should never be the case on composer install.)

So the question is why is it needed to run Flex on composer install? Shouldn't all receipes be executed only during updating commands like composer require or composer update?
Is it only to create .env files? This could easily be separated.

fabpot added a commit that referenced this issue Mar 9, 2019
This PR was merged into the 1.2-dev branch.

Discussion
----------

only write lock when its content has changed

Fixed #379 by only writing the Lockfile when something has changed (which is not the case on `composer install`).

This seems to me the best solution for the linked issue:
* no change in the Flex behaviour on `composer install` needed (still doing the same like on `composer update`)
* only update the Lockfile when needed (even the modification timestamp will stay the same)
* working for all composer actions (because of auto detection)

Thank you for your feedback.

Commits
-------

ffe345f only write lock when its content has changed
nicolas-grekas added a commit that referenced this issue Dec 13, 2019
This PR was squashed before being merged into the 1.5-dev branch.

Discussion
----------

compare data before marking lock as changed

In #479 I tried to fix the issue #379 by introducing a _changed_ flag to the Lock.

This patch worked for a few months. However, introducing #576 broke the patch by [always calling](https://github.com/symfony/flex/pull/576/files#diff-46b78198ae7ea525f04268205dd782c3R273) `set` ending in the same situation as before.

Blame on me for not checking if anything differs before setting the _changed_ flag. This PR tries to do better.

Commits
-------

bc400be compare data before marking lock as changed
tgalopin pushed a commit to tgalopin/flex that referenced this issue Dec 3, 2020
@redusek
Copy link

redusek commented Feb 16, 2021

How is this closed? It seems that composer install should not be attempting to update symfony.lock at all, but the solution is only to not update it unless recipes have changed? How is this acceptable? It shouldn't be updated even if recipes change. My expectation is that if it is not going to be able to install and use only what is in symfony.lock it should fail.

@kevinpapst
Copy link
Contributor

With a bit of luck this is finally fixed by #794

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants