When developing a Drupal module, you can use Composer to clone the Git repository locally and let Dogit manage the development process. By using Composer and Dogit for the Drupal development, a developer can do everything from the command line, which streamlines their workflow and automate their development process.
Dogit is a command line tool that lets you interact with Drupal.org Git repositories. It provides various commands for managing Drupal modules, themes and projects, such as creating issues, monitoring repositories and working with merge requests. In order to install Dogit, there are two steps to the process.
Install Dogit
To install this command line tool globally with Composer run the following,
composer global require dpi/dogit
The run the command dogit
and you should see output similar below.
$~ dogit
Usage:
command [options] [arguments]
.....
Available commands:
completion Dump the shell completion script
convert [cv]
help Display help for a command
list List commands
issue
issue:mr [imr] Interactively check out a MR for an issue.
issue:timeline [itl]
project
project:clone [pc]
project:mr [pmr] Interactively check out a MR for a project.
Use Composer install dev project
To use Composer to download the development version of a contributed modules GIT repository, use your composer.json and adding the prefer-source flag to clone the repository for more information on this flag review the documentation.
https://getcomposer.org/doc/03-cli.md
There are two ways of downloading a package: source and dist. Composer uses dist by default. If you pass --prefer-install=source (or --prefer-source) Composer will install from source if there is one. This is useful if you want to make a bugfix to a project and get a local git clone of the dependency directly. To get the legacy behavior where Composer use source automatically for dev versions of packages, use --prefer-install=auto. See also config.preferred-install. Passing this flag will override the config value.
Here is an example of how to use the `--prefer-source` flag from the command line:
composer require drupal/module_name:1.0.x-dev --prefer-source
As an example let's look at one of the contributed modules our team is developing Drupal.org. The output shows that the Composer is cloning the the repo(Cloning 2.0.0-beta6
).
$~ composer require drupal/browser_development:2.* --prefer-source
./composer.json has been updated
Running composer update drupal/browser_development
Loading composer repositories with package information
Updating dependencies
Lock file operations: 2 installs, 0 updates, 0 removals
- Locking drupal/browser_development (2.0.0-beta6)
- Locking scssphp/scssphp (v1.12.1)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 2 installs, 0 updates, 0 removals
- Syncing scssphp/scssphp (v1.12.1) into cache
- Syncing drupal/browser_development (2.0.0-beta6) into cache
- Installing scssphp/scssphp (v1.12.1): Cloning 394ed1e960 from cache
- Installing drupal/browser_development (2.0.0-beta6): Cloning 2.0.0-beta6 from cache
Below shows that the browser development Drupal module was GIT cloned to the contrib directory using Composer.
$~ pwd
.../web/modules/contrib
$~ ls -hal | grep browser_development
drwxr-xr-x@ 16 <redacted> Feb 23 18:03 browser_development
In our circumstance there is no dev branch but once the 9. branch was checkout development could start using Dogit.
$~ pwd
.../web/modules/contrib/browser_development
$~ git branch
* (HEAD detached at 2.0.0-beta6)
9.x-0.x
$~ git checkout 9.x-0.x
Switched to branch '9.x-0.x'
Your branch is up to date with 'origin/9.x-0.x'.
Then pull the latest version of the branch.
$~ git pull origin
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 2), reused 3 (delta 2), pack-reused 0
Unpacking objects: 100% (3/3), 333 bytes | 11.00 KiB/s, done.
From https://git.drupalcode.org/project/browser_development
f76c758..914e07f 9.x-0.x -> origin/9.x-0.x
Updating f76c758..914e07f
Fast-forward
README.md | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)