Adding an external repo to your composer.json

Submitted by daniel on Mon, 30/11/2020 - 16:45

Sometimes it may be useful to specify a patched branch of a particular project. I recently came across an issue where it was not possible to patch a module, but I was able to create an issue branch  and  pull request. Pending approval and review I was still able to reference this branch in my composer file, This was useful in this case as this particular dependency broke the composer pipeline, install update etc. Here I show you how this can be done.

1. Add Your repo

Under the repositories key, add an entry for the repository and branch that you would like to add. e.g.

  {
    "type": "vcs",
    "url": "git@git.drupal.org:issue/migrate_file-3148126.git"
  }

Here we specify the  type of repository i.e. "vcs" . We also specify the url and branch that we would like to reference. In this case we are using ssh to access the repo that contains the newly submitted branch. git@git.drupal.orgissue/migrate_file-3148126.git.  For this specific issue I have specified the use of ssh to access the repo . As this has not been approved I will need access from the machine that  runs Composer. In this case I have added my public key to the  repo on my host machine and  that is  where I will be running Composer from in this example in order to  circumvent any access  issues.

I also need  to  specify the project under the require  key. My entry looks like this:

    "drupal/migrate_file": "2.0.0.x-dev",

 Notice the syntax  around the version number. First of all this includes the  branch that I have created 2.0.0  and then it is suffixed .x-dev.

Thats it!  Simply run composer install and Composer should handle  everything as expected.This appears to be enough for composer to download your specified module  and branch using the repository credentials we configured earlier.

 

Add new comment