{"action":"created","issue":{"url":"https://api.github.com/repos/composer/composer/issues/3167","labels_url":"https://api.github.com/repos/composer/composer/issues/3167/labels{/name}","comments_url":"https://api.github.com/repos/composer/composer/issues/3167/comments","events_url":"https://api.github.com/repos/composer/composer/issues/3167/events","html_url":"https://github.com/composer/composer/issues/3167","id":38846171,"number":3167,"title":"Simplify to switch branches with different composer dependencies","user":{"login":"sun","id":41992,"avatar_url":"https://avatars.githubusercontent.com/u/41992?v=3","gravatar_id":"","url":"https://api.github.com/users/sun","html_url":"https://github.com/sun","followers_url":"https://api.github.com/users/sun/followers","following_url":"https://api.github.com/users/sun/following{/other_user}","gists_url":"https://api.github.com/users/sun/gists{/gist_id}","starred_url":"https://api.github.com/users/sun/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sun/subscriptions","organizations_url":"https://api.github.com/users/sun/orgs","repos_url":"https://api.github.com/users/sun/repos","events_url":"https://api.github.com/users/sun/events{/privacy}","received_events_url":"https://api.github.com/users/sun/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":5,"created_at":"2014-07-27T17:12:11Z","updated_at":"2016-01-27T15:09:04Z","closed_at":null,"body":"#### Scenario\r\n1. [PHPUnit](https://github.com/sebastianbergmann/phpunit) 4+ uses Composer, and it's in the process of major refactoring.\r\n1. In `master`, several utility classes have been split into separate, decoupled packages (or replaced with other 3rd party libs) that are pulled back in via Composer.\r\n1. In stable branches, those utility classes still exist and the additional Composer dependencies do not.\r\n1. The target branch for each PR varies a lot, depending on potential BC breaks, so the first thing you do before you do anything is to switch to a different target branch.\r\n\r\n#### Problem / Use-case\r\nCurrently, I need to perform the following procedure whenever I'm switching branches:\r\n\r\n1. Remove the auto-generated `composer.lock` file (PHPUnit has none by default)\r\n\r\n  ```sh\r\n  $ rm composer.lock\r\n  ```\r\n1. Run `composer install` to switch dependencies: (cleaned up for brevity)\r\n\r\n    ```diff\r\n    --- switch-to-master.txt\r\n    +++ switch-to-stable.txt\r\n    @@\r\n     $ composer install\r\n     Loading composer repositories with package information\r\n     Installing dependencies (including require-dev)\r\n       - Updating sebastian/environment\r\n    -    Checking out (1.0.0 => dev-master 10c7467)\r\n    +    Checking out (dev-master 10c7467 => 1.0.0)\r\n     \r\n       - Updating phpunit/php-token-stream\r\n    -    Checking out (1.2.2 => dev-master a080256)\r\n    +    Checking out (dev-master a080256 => 1.2.2)\r\n     \r\n       - Updating phpunit/php-code-coverage\r\n    -    Checking out (2.0.9 => dev-master 9171bca)\r\n    +    Checking out (dev-master 9171bca => 2.0.9)\r\n     \r\n    -  - Installing ocramius/lazy-map\r\n    -    Cloning (dev-master 5c77102)\r\n    +  - Removing ocramius/lazy-map\r\n    +    Was (dev-master)\r\n     \r\n    -  - Installing ocramius/instantiator\r\n    -    Loading (1.0.0) from cache\r\n    +  - Removing ocramius/instantiator\r\n    +    Was (1.0.0)\r\n     \r\n       - Updating phpunit/phpunit-mock-objects\r\n    -    Checking out (2.1.5 => dev-master f9f31b9)\r\n    +    Checking out (dev-master f9f31b9 => 2.1.5)\r\n     \r\n       - Updating sebastian/exporter\r\n    -    Checking out (1.0.1 => dev-master eb54a69)\r\n    +    Checking out (dev-master eb54a69 => 1.0.1)\r\n     \r\n       - Updating sebastian/diff\r\n    -    Checking out (1.1.0 => dev-master ac84cfd)\r\n    +    Checking out (dev-master ac84cfd => 1.1.0)\r\n     \r\n       - Updating sebastian/comparator\r\n    -    Checking out (1.0.0 => dev-master e54a01c)\r\n    +    Checking out (dev-master e54a01c => 1.0.0)\r\n     \r\n       - Updating symfony/yaml\r\n    -    Checking out (v2.5.2 => dev-master 07ff901)\r\n    +    Checking out (dev-master 07ff901 => v2.5.2)\r\n     \r\n     Writing lock file\r\n     Generating autoload files\r\n    ```\r\n\r\nIn particular, the suboptimal part:\r\n\r\nSome dependencies are removed entirely (and added back when switching back):\r\n>  - Removing ocramius/lazy-map\r\n>  - Removing ocramius/instantiator\r\n\r\nCoincidentally, for some reason, those two deps also seem to be supplied by dist instead of by source.  Not sure why that is.  If they were git clones, I can only assume that switching branches would take even longer, because the entire repo would be removed and re-cloned from scratch.\r\n\r\n#### Proposed solution\r\n\r\n1. `composer install --no-remove` — New option to not clean up extraneous vendor packages and retain them in-place, as-is.\r\n\r\n1. Optionally for UX: `composer switch` — New built-in command; controlled way for switching between branches.  Under the hood:\r\n  1. Determine whether `composer.lock` is under VCS control.  If not, delete it.\r\n  1. Invoke `composer install --no-remove`.\r\n  1. …possibly further A.I. improvements…\r\n\r\nThoughts?\r\n\r\n##### Notes\r\n\r\nI don't know whether there is a recommended solution or workaround for this, or whether I'm doing something wrong — didn't find anything in the docs; searching existing issues didn't yield anything either.\r\n\r\nIn any case:  It takes quite some time to figure out how to use Composer correctly for this (very common?) scenario, so just in case it's deemed to have to be so hard and no functional changes will be considered, we should at least consider to add a dedicated documentation section about the topic of switching between branches.\r\n\r\n##### Closely related issues\r\n* #1083 Git post-checkout/post-merge hook integration. (status unclear)\r\n* #197 New dedicated `clean` command. (rejected)\r\n\r\n##### Marginally related issues\r\n* #1013 composer.json inheritance. (WIP)\r\n* #2129 / #2325 Support multiple environments. (rejected)\r\n"},"comment":{"url":"https://api.github.com/repos/composer/composer/issues/comments/175675455","html_url":"https://github.com/composer/composer/issues/3167#issuecomment-175675455","issue_url":"https://api.github.com/repos/composer/composer/issues/3167","id":175675455,"user":{"login":"biwerr","id":6122710,"avatar_url":"https://avatars.githubusercontent.com/u/6122710?v=3","gravatar_id":"","url":"https://api.github.com/users/biwerr","html_url":"https://github.com/biwerr","followers_url":"https://api.github.com/users/biwerr/followers","following_url":"https://api.github.com/users/biwerr/following{/other_user}","gists_url":"https://api.github.com/users/biwerr/gists{/gist_id}","starred_url":"https://api.github.com/users/biwerr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/biwerr/subscriptions","organizations_url":"https://api.github.com/users/biwerr/orgs","repos_url":"https://api.github.com/users/biwerr/repos","events_url":"https://api.github.com/users/biwerr/events{/privacy}","received_events_url":"https://api.github.com/users/biwerr/received_events","type":"User","site_admin":false},"created_at":"2016-01-27T15:09:04Z","updated_at":"2016-01-27T15:09:04Z","body":"+1 "}}