function _drush_cm_merge_to_original_branch

7.x _drush_cm_merge_to_original_branch(&$merge_info)
1 call to _drush_cm_merge_to_original_branch()


commands/core/, line 1138
Provides Configuration Management commands.


function _drush_cm_merge_to_original_branch(&$merge_info) {
  $configuration_path = _drush_cm_get_configuration_path($merge_info);

  // Merge the results of the 3-way merge back to the original branch.
  drush_shell_cd_and_exec($configuration_path, 'git checkout %s', $merge_info['original-branch']);
  // Run 'git merge' and 'git commit' as separate operations, as 'git merge --squash'
  // seems to ignore the --commit option.
  $result = drush_shell_cd_and_exec($configuration_path, 'git merge --no-commit --squash %s', $merge_info['live-config']);
  if (!$result) {
    return drush_set_error('DRUSH_CONFIG_MERGE_FAILURE', dt("`git merge --squash` failed.  Output:\n\n!output", array('!output' => implode("\n", drush_shell_exec_output()))));

  // Re-import the merged changes into the database for the local site.
  drush_set_option('strict', 0);
  $result = drush_invoke('config-import', array($merge_info['config_label']));
  if ($result === FALSE) {
    // If there was an error, or nothing to import, return FALSE,
    // signaling rollback.
    return FALSE;

  // Check to see if the merge resulted in any changed files.
  // If there were no changes in dev, then there might not be
  // anything to do here.
  $result = drush_shell_cd_and_exec($configuration_path, 'git status --porcelain .');
  if (!$result) {
    return drush_set_error('DRUSH_CONFIG_MERGE_FAILURE', dt("`git status` failed."));
  $files_changed_by_merge = drush_shell_exec_output();

  // If there were any files changed in the merge, then import them and commit.
  if (!empty($files_changed_by_merge)) {
    if ($merge_info['commit']) {
      if (empty($merge_info['message'])) {
        // The 'dev-site' is probably just '@self', so we'll put the site-name
        // in the comment, which hopefully will read okay
        $config = Drupal::config('');
        $site_name = $config->get('name');
        $merge_info['message'] = dt("Merged configuration from !live in !site", array('!live' => $merge_info['live-site'], '!site' => $site_name));

        // Retrieve a list of differences between the active and target configuration (if any).
        $target_storage = new FileStorage($configuration_path);
        /** @var \Drupal\Core\Config\StorageInterface $active_storage */
        $active_storage = new FileStorage($merge_info['original_configuration_files']);
        $config_comparer = new StorageComparer($active_storage, $target_storage, Drupal::service('config.manager'));
        if ($config_comparer->createChangelist()->hasChanges()) {
          $change_list = array();
          foreach ($config_comparer->getAllCollectionNames() as $collection) {
            $change_list[$collection] = $config_comparer->getChangelist(NULL, $collection);
          $tbl = _drush_format_config_changes_table($change_list);
          $output = $tbl->getTable();
          if (!stristr(PHP_OS, 'WIN')) {
            $output = str_replace("\r\n", PHP_EOL, $output);
          $merge_info['message'] .= "\n\n$output";
      $comment_file = drush_save_data_to_temp_file($merge_info['message']);
      $result = drush_shell_cd_and_exec($configuration_path, 'git commit --file=%s', $comment_file);
      if (!$result) {
        return drush_set_error('DRUSH_CONFIG_MERGE_FAILURE', dt("`git commit` failed."));
  return TRUE;