function _drush_cm_get_initial_vcs_state

7.x config.drush.inc _drush_cm_get_initial_vcs_state(&$merge_info)
1 call to _drush_cm_get_initial_vcs_state()

File

commands/core/config.drush.inc, line 814
Provides Configuration Management commands.

Code

function _drush_cm_get_initial_vcs_state(&$merge_info) {
  $configuration_path = _drush_cm_get_configuration_path($merge_info);
  // Is the selected configuration directory under git revision control?  If not, fail.
  $result = drush_shell_cd_and_exec($configuration_path, 'git rev-parse --abbrev-ref HEAD');
  if (!$result) {
    return drush_set_error('DRUSH_CONFIG_MERGE_NO_GIT', dt("The drush config-merge command requires that the selected configuration directory !dir be under git revision control.", array('!dir' => $configuration_path)));
  }
  $output = drush_shell_exec_output();
  $original_branch = $output[0];
  drush_log(dt("Original branch is !branch", array('!branch' => $original_branch)), 'debug');
  $merge_info['original-branch'] = $original_branch;

  // Find the current sha-hash
  $result = drush_shell_cd_and_exec($configuration_path, 'git rev-parse HEAD');
  if (!$result) {
    return drush_set_error('DRUSH_CONFIG_MERGE_NO_GIT', dt("`git rev-parse HEAD` failed."));
  }
  $output = drush_shell_exec_output();
  $merge_info['original_hash'] = $output[0];

  // Fail if there are any uncommitted changes on the current branch
  // inside the configuration path.
  $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."));
  }
  $uncommitted_changes = drush_shell_exec_output();
  if (!empty($uncommitted_changes)) {
    return drush_set_error('DRUSH_CONFIG_MERGE_UNCOMMITTED_CHANGES', dt("Working set has uncommitted changes; please commit or discard them before merging.  `git stash` before `drush config-merge`, and `git stash pop` afterwards can be useful here.\n\n!changes", array('!changes' => $uncommitted_changes)));
  }
}