6

I want to install a local Drupal site in such a way that Drupal core is a git repository so I can work on patches.

Just doing a git clone doesn't work, because I also need tools such as Drush, and installing those in a git clone of core changes the composer.json file that belongs to core.

What's the correct way of doing this?

1
1

I am not sure if there really is a correct, or best way. All of the core devs I have interacted with have their own setup that works best for them.

My general setup is

  • directory per remote branch: right now I have drupal-8.8.x, drupal 8.9.x, and drupal 9.0.x
  • git branch for each patch that is in the issue-comment form: 3113284-02, 3113284-04)

I do this because I have a bunch of shell scripts for installing, cleaning, diffing, generating patches, running tests, etc. All of these scripts get ignored.

As far as drush goes, I keep a global install and checkout a tag periodically. I then have a .envrc in each branch directory to $PATH everything correctly. This prevents changes to composer.json.

However, there are some things you can try. A while ago, running tests locally with certain PHP versions meant updating phpunit via a post-composer script. You then had to restore composer.json and composer.lock before running a git diff ... to generate a patch/interdiff. You can do the something similar with drush:

  • git pull origin/8.8.x
  • composer require drush/drush:^10
  • git checkout composer.json composer.lock

The above approach is on my short-list for updates to my scripts.

4
  • How do you install Drupal in the first place -- is it just a git clone that you then run composer install on? – joachim Feb 17 '20 at 10:51
  • @joachim Yeah, git clone, checkout the branch I want, then composer install. You want a git clone of the official repo so that the git indexes matches up when you have tricky applies/rerolls. – mpdonadio Feb 17 '20 at 16:12
  • And then you're forever having to muck about with the composer.lock file when you want to make patches, aren't you? – joachim Feb 19 '20 at 10:05
  • @joachim No, if I mess with composer.json or composer.lock, I just restore it to origin afterwards. If I don't, then the lockfile never changes. I have never found it to be a hassle. The core dependencies are mostly stable; they tend to change near a release if bumping the Symfony point releases change. I worked on at least five issues this weekend, and don't think I needed to worry about composer once. – mpdonadio Feb 19 '20 at 13:24
1

I solve this by installing Drush separately (I'm still using Drush 8), then I can run Drush commands on installs of Drupal that are downloaded with git.

5
  • That's not sustainable though -- Drush 8 is deprecated surely? – joachim Feb 17 '20 at 16:19
  • 1
    Drush 8 kinda needs to live as long as Drupal 7 does, because Drush 9+ only work with Drupal 8+. – Damien McKenna Feb 18 '20 at 18:43
  • Also, what about things like Devel module? – joachim Feb 27 '20 at 13:52
  • Every other module I work on (I have a few hundred downloaded locally) is downloaded manually using git - you don't need composer to do that. – Damien McKenna Feb 28 '20 at 14:20
  • That's only viable for now because they don't have their own composer dependencies! – joachim Mar 11 '20 at 10:42
1

I followed the preferred-install source like I documented for contrib modules which fits my needs.

composer create-project --no-install drupal/recommended-project:8.8.x-dev se-291135
cd se-291135/

This results in a require of ^8.8 (like 8.8.2) so we need to edit composer.json and change all those occurrences into 8.8.x-dev and add the preferred-install

    "config": {
        "preferred-install": {
            "drupal/core": "source",
            "*": "dist"
        },
        ...

Not sure why I had to remove the lock file :-/

rm composer.lock

Installing with these settings we get a drupal/code in web/core with a detached head. Fix that and we are almost done.

composer install
cd web/core
git checkout origin/8.8.x

To make sure our patches matches drupal a git diff alias would help like

alias corediff='git diff --src-prefix=a/core/ --dst-prefix=b/core/'
1
  • How does Composer react to changing the git checkout of core? Won't it try to revert that anytime you do a composer update or composer install? How do you add Drush? – joachim Feb 19 '20 at 10:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.