Skip to content

Commit 96e8fa1

Browse files
committed
fix: Install drush without affecting git index
1 parent cd06f6c commit 96e8fa1

File tree

3 files changed

+57
-0
lines changed

3 files changed

+57
-0
lines changed

commands/web/drush

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
#ddev-generated
4+
## Description: Run drush CLI inside the web container, installing it if necessary
5+
## Usage: drush [flags] [args]
6+
## Example: "ddev drush uli" or "ddev drush sql-cli" or "ddev drush --version"
7+
## ProjectTypes: drupal7,drupal8,drupal9,drupal10,drupal,backdrop
8+
## ExecRaw: true
9+
10+
if ! command -v drush >/dev/null; then
11+
echo "drush is not yet installed. Installing it...'"
12+
.ddev/core-dev/install_drush.sh
13+
fi
14+
drush "$@"

core-dev/install_drush.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
#ddev-generated
4+
# This script installs drush/drush without changing the git
5+
# status of the Drupal checkout
6+
7+
set -eu -o pipefail
8+
9+
if command -v drush >/dev/null; then
10+
echo "drush is already installed, taking no action. You can remove it if you want to reinstall"
11+
exit
12+
fi
13+
14+
echo "Installing drush without affecting git status"
15+
16+
# Make certain that we have something staged so we can create stash
17+
touch .makedrush.txt
18+
git add .makedrush.txt
19+
20+
# Save the stash, which will include anything people were doing
21+
# plus the .makedrush.txt. This gets us back to "no changes"
22+
# in `git status`
23+
git stash
24+
25+
# Install drush
26+
composer require drush/drush
27+
28+
# Roll back to what we started with. Cleans up
29+
# composer.* and anything else that the drush install changes
30+
# But vendor directory is untouched since
31+
# it's gitignored
32+
git reset --hard
33+
34+
# Restore anything that might have been staged
35+
# prior to the start
36+
git stash apply
37+
38+
# Get rid of our dummy file
39+
git rm -f .makedrush.txt
40+
41+
echo "drush/drush is installed in $(which drush)"

install.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ project_files:
88
- core-dev/phpunit-firefox.xml
99
- core-dev/phpunit-chrome.xml
1010
- commands/web/drupal
11+
- commands/web/drush
1112
- commands/web/phpunit
1213
- commands/web/nightwatch
14+
- core-dev/install_drush.sh
1315
- core-dev/gitignore
1416
- core-dev/.env
1517
- core-dev/src/Command/AdminLoginCommand.php

0 commit comments

Comments
 (0)