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