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_pm_version_control_svn implements drush_pm_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. $status_files = implode(' ', array_keys($items_to_test));
  13. // Check the project directory looks clean
  14. if (drush_shell_exec('cd ' . $project['full_project_path'] . ' && svn status '. drush_get_option('svnstatusparams') .' '. $status_files)) {
  15. $output = preg_grep('/^[ ACDMRX?!~][ CM][ L][ +][ SX][ K]/', drush_shell_exec_output());
  16. if (!empty($output)) {
  17. return drush_set_error('DRUSH_PM_SVN_LOCAL_CHANGES', dt("The SVN working copy at !path appears to have uncommmitted changes (see below). Please commit or revert these changes before continuing:\n!output", array('!path' => $project['full_project_path'], '!output' => implode("\n", $output))));
  18. }
  19. }
  20. else {
  21. 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()))));
  22. }
  23. // Check for incoming updates
  24. if (drush_shell_exec('cd ' . $project['full_project_path'] . ' && svn status -u '. drush_get_option('svnstatusparams') .' '. $status_files)) {
  25. $output = preg_grep('/\*/', drush_shell_exec_output());
  26. if (!empty($output)) {
  27. 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))));
  28. }
  29. }
  30. else {
  31. 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 Subversion \ninstalled, that this directory is a subversion working copy and 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()))));
  32. }
  33. return TRUE;
  34. }
  35. /**
  36. * Implementation of rollback().
  37. */
  38. public function rollback($project) {
  39. if (drush_shell_exec('svn revert '. drush_get_option('svnrevertparams') .' '. $project['full_project_path'])) {
  40. $output = drush_shell_exec_output();
  41. if (!empty($output)) {
  42. return drush_set_error('DRUSH_PM_SVN_LOCAL_CHANGES', dt("The SVN working copy at !path appears to have uncommmitted changes (see below). Please commit or revert these changes before continuing:\n!output", array('!path' => $project['full_project_path'], '!output' => implode("\n", $output))));
  43. }
  44. }
  45. else {
  46. 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()))));
  47. }
  48. }
  49. /**
  50. * Implementation of post_update().
  51. */
  52. public function post_update($project) {
  53. if ($this->sync($project)) {
  54. // Only attempt commit on a sucessful sync
  55. $this->commit($project);
  56. }
  57. }
  58. /**
  59. * Implementation of post_download().
  60. */
  61. public function post_download($project) {
  62. if ($this->sync($project)) {
  63. // Only attempt commit on a sucessful sync
  64. $this->commit($project);
  65. }
  66. }
  67. /**
  68. * Automatically add any unversioned files to Subversion and remove any files
  69. * that have been deleted on the file system
  70. */
  71. private function sync($project) {
  72. if (drush_get_option('svnsync')) {
  73. $errors = '';
  74. if (drush_shell_exec('svn status '. drush_get_option('svnstatusparams') .' '. $project['full_project_path'])) {
  75. $output = drush_shell_exec_output();
  76. foreach ($output as $line) {
  77. if (preg_match('/^\? *(.*)/', $line, $matches)) {
  78. if (!drush_shell_exec('svn add '. drush_get_option('svnaddparams') .' '. $matches[1])) {
  79. $errors .= implode("\n", drush_shell_exec_output());
  80. }
  81. }
  82. if (preg_match('/^\! *(.*)/', $line, $matches)) {
  83. if (!drush_shell_exec('svn remove '. drush_get_option('svnremoveparams') .' '. $matches[1])) {
  84. $errors .= implode("\n", drush_shell_exec_output());
  85. }
  86. }
  87. }
  88. if (!empty($errors)) {
  89. 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)));
  90. }
  91. }
  92. else {
  93. 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()))));
  94. }
  95. return TRUE;
  96. }
  97. }
  98. /**
  99. * Automatically commit changes to the repository
  100. */
  101. private function commit($project) {
  102. if (drush_get_option('svncommit')) {
  103. $message = drush_get_option('svnmessage');
  104. if (empty($message)) {
  105. $message = dt("Drush automatic commit: \n") . implode(' ', $_SERVER['argv']);
  106. }
  107. if (drush_shell_exec('svn commit '. drush_get_option('svncommitparams') .' -m "'. $message .'" '. $project['full_project_path'])) {
  108. drush_log(dt('Project committed to Subversion successfully'), 'ok');
  109. }
  110. else {
  111. 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()))));
  112. }
  113. }
  114. else {
  115. drush_print(dt("You should consider committing the new code to your Subversion repository.\nIf this version becomes undesireable, use Subversion to roll back."));
  116. }
  117. }
  118. }