bzr.inc

  1. 8.0.x commands/pm/version_control/bzr.inc
  2. 6.x commands/pm/version_control/bzr.inc
  3. 7.x commands/pm/version_control/bzr.inc
  4. 3.x commands/pm/version_control/bzr.inc
  5. 4.x commands/pm/version_control/bzr.inc
  6. 5.x commands/pm/version_control/bzr.inc
  7. master commands/pm/version_control/bzr.inc

Drush pm Bazaar extension

Classes

File

commands/pm/version_control/bzr.inc
View source
  1. <?php
  2. /**
  3. * @file Drush pm Bazaar extension
  4. */
  5. class drush_version_control_bzr implements drush_version_control {
  6. /**
  7. * Implementation of pre_update().
  8. *
  9. * Check that the project or drupal core directory looks clean
  10. */
  11. public function pre_update(&$project, $items_to_test = array()) {
  12. // Bazaar needs a list of items to test within the given project.
  13. // If $items_to_test is empty we need to force it to test the project
  14. // directory itself --once we've cd'ed to it.
  15. if (empty($items_to_test)) {
  16. $items_to_test = array('.' => '.');
  17. }
  18. $args = array_keys($items_to_test);
  19. array_unshift($args, 'bzr status --short' . str_repeat(' %s', count($args)));
  20. array_unshift($args, $project['full_project_path']);
  21. if (call_user_func_array('drush_shell_cd_and_exec', $args)) {
  22. $output = preg_grep('/^[\sRCP][\sNDKM][\s\*]/', drush_shell_exec_output());
  23. if (!empty($output)) {
  24. return drush_set_error('DRUSH_PM_BZR_LOCAL_CHANGES', dt("The Bazaar working copy at !path appears to have uncommitted changes (see below). Please commit or revert these changes before continuing:\n!output", array('!path' => $project['full_project_path'], '!output' => implode("\n", $output))));
  25. }
  26. }
  27. else {
  28. return drush_set_error('DRUSH_PM_BZR_NOT_FOUND', dt("Drush was unable to get the bzr status on !path. Check that you have Bazaar \ninstalled and that this directory is a Bazaar working copy.\nThe specific errors are below:\n!errors", array('!path' => $project['full_project_path'], '!errors' => implode("\n", drush_shell_exec_output()))));
  29. }
  30. return TRUE;
  31. }
  32. /**
  33. * Implementation of rollback().
  34. */
  35. public function rollback($project) {
  36. if (drush_shell_exec('bzr revert %s', $project['full_project_path'])) {
  37. $output = drush_shell_exec_output();
  38. if (!empty($output)) {
  39. return drush_set_error('DRUSH_PM_BZR_LOCAL_CHANGES', dt("The Bazaar working copy at !path appears to have uncommitted changes (see below). Please commit or revert these changes before continuing:\n!output", array('!path' => $project['full_project_path'], '!output' => implode("\n", $output))));
  40. }
  41. }
  42. else {
  43. return drush_set_error('DRUSH_PM_BZR_NOT_FOUND', dt("Drush was unable to get the Bazaar status on !path. Check that you have Bazaar \ninstalled and that this directory is a Bazaar working copy.\nThe specific errors are below:\n!errors", array('!path' => $project['full_project_path'], '!errors' => implode("\n", drush_shell_exec_output()))));
  44. }
  45. }
  46. /**
  47. * Implementation of post_update().
  48. */
  49. public function post_update($project) {
  50. if ($this->sync($project)) {
  51. // Only attempt commit on a sucessful sync
  52. $this->commit($project);
  53. }
  54. }
  55. /**
  56. * Implementation of post_download().
  57. */
  58. public function post_download($project) {
  59. if ($this->sync($project)) {
  60. // Only attempt commit on a sucessful sync
  61. $this->commit($project);
  62. }
  63. }
  64. /**
  65. * Automatically add any unversioned files to Bazaar and remove any files
  66. * that have been deleted on the file system
  67. */
  68. private function sync($project) {
  69. if (drush_get_option('bzrsync')) {
  70. $errors = '';
  71. $root = array();
  72. if (drush_shell_exec('bzr status --short %s', $project['full_project_path'])) {
  73. $output = drush_shell_exec_output();
  74. // All paths returned by bzr status are relative to the repository root.
  75. if (drush_shell_exec('bzr root %s', $project['full_project_path'])) {
  76. $root = drush_shell_exec_output();
  77. }
  78. foreach ($output as $line) {
  79. if (preg_match('/^\?\s+(.*)/', $line, $matches)) {
  80. $path = $root[0] .'/'. $matches[1];
  81. if (!drush_shell_exec('bzr add --no-recurse %s', $path)) {
  82. $errors .= implode("\n", drush_shell_exec_output());
  83. }
  84. }
  85. else if (preg_match('/^\s+D\s+(.*)/', $line, $matches)) {
  86. $path = $root[0] .'/'. $matches[1];
  87. if (!drush_shell_exec('bzr remove %s', $path)) {
  88. $errors .= implode("\n", drush_shell_exec_output());
  89. }
  90. }
  91. }
  92. if (!empty($errors)) {
  93. return drush_set_error('DRUSH_PM_BZR_SYNC_PROBLEMS', dt("Problems were encountered adding or removing files to/from Bazaar.\nThe specific errors are below:\n!errors", array('!errors' => $errors)));
  94. }
  95. }
  96. else {
  97. return drush_set_error('DRUSH_PM_BZR_NOT_FOUND', dt("Drush was unable to get the bzr status. Check that you have Bazaar \ninstalled and that the site is a Bazaar working copy.\nThe specific errors are below:\n!errors", array('!errors' => implode("\n", drush_shell_exec_output()))));
  98. }
  99. return TRUE;
  100. }
  101. }
  102. /**
  103. * Automatically commit changes to the repository
  104. */
  105. private function commit($project) {
  106. if (drush_get_option('bzrcommit')) {
  107. $message = drush_get_option('bzrmessage');
  108. if (empty($message)) {
  109. $message = dt("Drush automatic commit.\nProject: @name @type\nCommand: @arguments", array('@name' => $project['name'], '@type' => $project['project_type'], '@arguments' => implode(' ', $_SERVER['argv'])));
  110. }
  111. if (drush_shell_exec('bzr commit --message=%s %s', $message, $project['full_project_path'])) {
  112. drush_log(dt('Project committed to Bazaar successfully'), 'ok');
  113. }
  114. else {
  115. drush_set_error('DRUSH_PM_BZR_COMMIT_PROBLEMS', dt("Problems were encountered committing your changes to Bazaar.\nThe specific errors are below:\n!errors", array('!errors' => implode("\n", drush_shell_exec_output()))));
  116. }
  117. }
  118. else {
  119. drush_print(dt("You should consider committing the new code to your Bazaar repository.\nIf this version becomes undesireable, use Bazaar to roll back."));
  120. }
  121. }
  122. public static function reserved_files() {
  123. return array('.bzr', '.bzrignore', '.bzrtags');
  124. }
  125. }