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 Drush pm SVN extension
  4. */
  5. class drush_version_control_svn implements drush_version_control {
  6. /**
  7. * Implementation of pre_update().
  8. */
  9. public function pre_update(&$project, $items_to_test = array()) {
  10. // If items to test is empty, test everything; otherwise, pass just
  11. // the list of files to test to svn status.
  12. $args = array_keys($items_to_test);
  13. array_unshift($args, 'svn status '. drush_get_option('svnstatusparams') . str_repeat('%s ', count($args)));
  14. array_unshift($args, $project['full_project_path']);
  15. if (call_user_func_array('drush_shell_cd_and_exec', $args)) {
  16. $output = preg_grep('/^[ ACDMRX?!~][ CM][ L][ +][ SX][ K]/', drush_shell_exec_output());
  17. if (!empty($output)) {
  18. 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))));
  19. }
  20. }
  21. else {
  22. 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()))));
  23. }
  24. // Check for incoming updates
  25. $args = array_keys($items_to_test);
  26. array_unshift($args, 'svn status -u '. drush_get_option('svnstatusparams') . str_repeat('%s ', count($args)));
  27. array_unshift($args, $project['full_project_path']);
  28. if (call_user_func_array('drush_shell_cd_and_exec', $args)) {
  29. $output = preg_grep('/\*/', drush_shell_exec_output());
  30. if (!empty($output)) {
  31. 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))));
  32. }
  33. }
  34. else {
  35. 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()))));
  36. }
  37. return TRUE;
  38. }
  39. /**
  40. * Implementation of rollback().
  41. */
  42. public function rollback($project) {
  43. if (drush_shell_exec('svn revert '. drush_get_option('svnrevertparams') .' '. $project['full_project_path'])) {
  44. $output = drush_shell_exec_output();
  45. if (!empty($output)) {
  46. 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))));
  47. }
  48. }
  49. else {
  50. 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()))));
  51. }
  52. }
  53. /**
  54. * Implementation of post_update().
  55. */
  56. public function post_update($project) {
  57. if ($this->sync($project)) {
  58. // Only attempt commit on a sucessful sync
  59. $this->commit($project);
  60. }
  61. }
  62. /**
  63. * Implementation of post_download().
  64. */
  65. public function post_download($project) {
  66. if ($this->sync($project)) {
  67. // Only attempt commit on a sucessful sync
  68. $this->commit($project);
  69. }
  70. }
  71. /**
  72. * Automatically add any unversioned files to Subversion and remove any files
  73. * that have been deleted on the file system
  74. */
  75. private function sync($project) {
  76. if (drush_get_option('svnsync')) {
  77. $errors = '';
  78. if (drush_shell_exec('svn status '. drush_get_option('svnstatusparams') .' '. $project['full_project_path'])) {
  79. $output = drush_shell_exec_output();
  80. foreach ($output as $line) {
  81. if (preg_match('/^\? *(.*)/', $line, $matches)) {
  82. if (!drush_shell_exec('svn add '. drush_get_option('svnaddparams') .' '. $matches[1])) {
  83. $errors .= implode("\n", drush_shell_exec_output());
  84. }
  85. }
  86. if (preg_match('/^\! *(.*)/', $line, $matches)) {
  87. if (!drush_shell_exec('svn remove '. drush_get_option('svnremoveparams') .' '. $matches[1])) {
  88. $errors .= implode("\n", drush_shell_exec_output());
  89. }
  90. }
  91. }
  92. if (!empty($errors)) {
  93. 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)));
  94. }
  95. }
  96. else {
  97. 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()))));
  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('svncommit')) {
  107. $message = drush_get_option('svnmessage');
  108. if (empty($message)) {
  109. $message = dt("Drush automatic commit: \n") . implode(' ', $_SERVER['argv']);
  110. }
  111. if (drush_shell_exec('svn commit '. drush_get_option('svncommitparams') .' -m "'. $message .'" '. $project['full_project_path'])) {
  112. drush_log(dt('Project committed to Subversion successfully'), 'ok');
  113. }
  114. else {
  115. 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()))));
  116. }
  117. }
  118. else {
  119. drush_print(dt("You should consider committing the new code to your Subversion repository.\nIf this version becomes undesireable, use Subversion to roll back."));
  120. }
  121. }
  122. public static function reserved_files() {
  123. return array('.svn');
  124. }
  125. }