svn.inc

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

Drush pm SVN extension

Classes

File

commands/pm/version_control/svn.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Drush pm SVN extension
  5. */
  6. class drush_version_control_svn implements drush_version_control {
  7. /**
  8. * Implementation of pre_update().
  9. */
  10. public function pre_update(&$project, $items_to_test = array()) {
  11. // If items to test is empty, test everything; otherwise, pass just
  12. // the list of files to test to svn status.
  13. $args = array_keys($items_to_test);
  14. array_unshift($args, 'svn status '. drush_get_option('svnstatusparams') . str_repeat('%s ', count($args)));
  15. array_unshift($args, $project['full_project_path']);
  16. if (call_user_func_array('drush_shell_cd_and_exec', $args)) {
  17. $output = preg_grep('/^[ ACDMRX?!~][ CM][ L][ +][ SX][ K]/', drush_shell_exec_output());
  18. if (!empty($output)) {
  19. return drush_set_error('DRUSH_PM_SVN_LOCAL_CHANGES', dt("The SVN 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))));
  20. }
  21. }
  22. else {
  23. return drush_set_error('DRUSH_PM_SVN_NOT_FOUND', dt("Drush was unable to get the svn status on !path.\nThe specific errors are below:\n!errors", array('!path' => $project['full_project_path'], '!errors' => implode("\n", drush_shell_exec_output()))));
  24. }
  25. // Check for incoming updates
  26. $args = array_keys($items_to_test);
  27. array_unshift($args, 'svn status -u '. drush_get_option('svnstatusparams') . str_repeat('%s ', count($args)));
  28. array_unshift($args, $project['full_project_path']);
  29. if (call_user_func_array('drush_shell_cd_and_exec', $args)) {
  30. $output = preg_grep('/\*/', drush_shell_exec_output());
  31. if (!empty($output)) {
  32. return drush_set_error('DRUSH_PM_SVN_REMOTE_CHANGES', dt("The SVN working copy at !path appears to be out of date with the repository (see below). Please run 'svn update' to pull down changes before continuing:\n!output", array('!path' => $project['full_project_path'], '!output' => implode("\n", $output))));
  33. }
  34. }
  35. else {
  36. return drush_set_error('DRUSH_PM_SVN_NOT_FOUND', dt("Drush was unable to get the svn remote status on !path. Check that you have connectivity to the repository.\nThe specific errors are below:\n!errors", array('!path' => $project['full_project_path'], '!errors' => implode("\n", drush_shell_exec_output()))));
  37. }
  38. return TRUE;
  39. }
  40. /**
  41. * Implementation of rollback().
  42. */
  43. public function rollback($project) {
  44. if (drush_shell_exec('svn revert '. drush_get_option('svnrevertparams') .' '. $project['full_project_path'])) {
  45. $output = drush_shell_exec_output();
  46. if (!empty($output)) {
  47. return drush_set_error('DRUSH_PM_SVN_LOCAL_CHANGES', dt("The SVN 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))));
  48. }
  49. }
  50. else {
  51. return drush_set_error('DRUSH_PM_SVN_NOT_FOUND', dt("Drush was unable to get the svn status on !path. Check that you have Subversion \ninstalled and that this directory is a subversion working copy.\nThe specific errors are below:\n!errors", array('!path' => $project['full_project_path'], '!errors' => implode("\n", drush_shell_exec_output()))));
  52. }
  53. }
  54. /**
  55. * Implementation of post_update().
  56. */
  57. public function post_update($project) {
  58. if ($this->sync($project)) {
  59. // Only attempt commit on a sucessful sync
  60. $this->commit($project);
  61. }
  62. }
  63. /**
  64. * Implementation of post_download().
  65. */
  66. public function post_download($project) {
  67. if ($this->sync($project)) {
  68. // Only attempt commit on a sucessful sync
  69. $this->commit($project);
  70. }
  71. }
  72. /**
  73. * Automatically add any unversioned files to Subversion and remove any files
  74. * that have been deleted on the file system
  75. */
  76. private function sync($project) {
  77. if (drush_get_option('svnsync')) {
  78. $errors = '';
  79. if (drush_shell_exec('svn status '. drush_get_option('svnstatusparams') .' '. $project['full_project_path'])) {
  80. $output = drush_shell_exec_output();
  81. foreach ($output as $line) {
  82. if (preg_match('/^\? *(.*)/', $line, $matches)) {
  83. if (!drush_shell_exec('svn add '. drush_get_option('svnaddparams') .' '. $matches[1])) {
  84. $errors .= implode("\n", drush_shell_exec_output());
  85. }
  86. }
  87. if (preg_match('/^\! *(.*)/', $line, $matches)) {
  88. if (!drush_shell_exec('svn remove '. drush_get_option('svnremoveparams') .' '. $matches[1])) {
  89. $errors .= implode("\n", drush_shell_exec_output());
  90. }
  91. }
  92. }
  93. if (!empty($errors)) {
  94. return drush_set_error('DRUSH_PM_SVN_SYNC_PROBLEMS', dt("Problems were encountered adding or removing files to/from this SVN working copy.\nThe specific errors are below:\n!errors", array('!errors' => $errors)));
  95. }
  96. }
  97. else {
  98. return drush_set_error('DRUSH_PM_SVN_NOT_FOUND', dt("Drush was unable to get the svn status on !path. Check that you have Subversion \ninstalled and that this directory is a subversion working copy.\nThe specific errors are below:\n!errors", array('!path' => $project['full_project_path'], '!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('svncommit')) {
  108. $message = drush_get_option('svnmessage');
  109. if (empty($message)) {
  110. $message = dt("Drush automatic commit: \n") . implode(' ', $_SERVER['argv']);
  111. }
  112. if (drush_shell_exec('svn commit '. drush_get_option('svncommitparams') .' -m "'. $message .'" '. $project['full_project_path'])) {
  113. drush_log(dt('Project committed to Subversion successfully'), 'ok');
  114. }
  115. else {
  116. drush_set_error('DRUSH_PM_SVN_COMMIT_PROBLEMS', dt("Problems were encountered committing your changes to Subversion.\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 Subversion repository.\nIf this version becomes undesireable, use Subversion to roll back."));
  121. }
  122. }
  123. public static function reserved_files() {
  124. return array('.svn');
  125. }
  126. }