9

Is there any way to check for differences with config in Drush 8?

I checked the list of drush 8 config commands and I couldn't find anything.

The reason I need this is that I have a site that runs behat tests via CircleCI, and sometimes I need to import the configuration more than once. So, I wanted to write a bash script that uses Drush to check whether there are any configuration differences, and if so, automatically re-imports the config in a loop until there are no more differences.

I'm stuck on Drush 8 because the behat extension only supports Drush 8.

1
  • 2
    You could probably pull in the config:status command from drush 9 into a module? Or use drush 8 globally, and drush 9 locally?
    – mradcliffe
    Jan 11, 2019 at 13:16

3 Answers 3

4

drush cim --diff

Since drush 9 there is a diff option that gives a diff on the config in code vs config in database

drush cex --diff

reverses the order of diff

8

The Drush 8 commands config:export (cex) and config:import (cim) accept a --no to prevent the actual import or export.

This allows you to write an if statement in Bash. Here is an example:

if drush config:import --no | grep file.settings; then 
  # Do something
  echo "Found in diff"; 
fi

In Drush 9 and 10, the return value $? will tell you if there are differences between the database and the directory containing YAML files:

  • 0 means no differences
  • 1 means differences

Drush 9 and 10 also accept a parameter --diff. If there are differences, Drush will print them.

1
  • Thanks to @Gogowitsch for --no. I'm using the next combination for a large diffs: drush cim --diff --no > config.diff and then grep whatever you need. Feb 23 at 18:12
3

If you have Drupal console installed, you could try config:diff

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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