diff --git a/app/Controller/ServersController.php b/app/Controller/ServersController.php index 16bd050da..e8d5af99c 100644 --- a/app/Controller/ServersController.php +++ b/app/Controller/ServersController.php @@ -1823,9 +1823,19 @@ class ServersController extends AppController $result = $this->Server->checkoutMain(); } - public function update() + public function update($branch = false) { if ($this->request->is('post')) { + $branch = false; + $filterData = array( + 'request' => $this->request, + 'named_params' => $this->params['named'], + 'paramArray' => ['branch'], + 'ordered_url_params' => @compact($paramArray), + 'additional_delimiters' => PHP_EOL + ); + $exception = false; + $settings = $this->_harvestParameters($filterData, $exception); $status = $this->Server->getCurrentGitStatus(); $raw = array(); if (empty($status['branch'])) { // do not try to update if you are not on branch @@ -1833,7 +1843,7 @@ class ServersController extends AppController $raw[] = $msg; $update = $msg; } else { - $update = $this->Server->update($status, $raw); + $update = $this->Server->update($status, $raw, $settings); } if ($this->_isRest()) { return $this->RestResponse->viewData(array('results' => $raw), $this->response->type()); diff --git a/app/Model/Server.php b/app/Model/Server.php index d45cca956..07352b498 100644 --- a/app/Model/Server.php +++ b/app/Model/Server.php @@ -3924,7 +3924,7 @@ class Server extends AppModel return implode('\n', $result); } - public function update(array $status, &$raw = array()) + public function update(array $status, &$raw = [], array $settings = []) { $final = ''; $workingDirectoryPrefix = 'cd $(git rev-parse --show-toplevel) && '; @@ -3943,7 +3943,18 @@ class Server extends AppModel ); $final .= implode("\n", $output) . "\n\n"; } - $command1 = $workingDirectoryPrefix . 'git pull origin ' . $status['branch'] . ' 2>&1'; + if (!empty($settings['branch'])) { + $branchname = preg_match('/$[a-z0-9\_]+/i', $settings['branch']); + $checkout_command = $workingDirectoryPrefix . 'git checkout ' . escapeshellarg($branchname) . ' 2>&1'; + exec($checkout_command, $output, $returnCode); + $raw[] = array( + 'input' => $command1, + 'output' => $output, + 'status' => $returnCode, + ); + $status = $this->getCurrentGitStatus(); + } + $command1 = $workingDirectoryPrefix . 'git pull origin ' . escapeshellarg($status['branch']) . ' 2>&1'; $command2 = $workingDirectoryPrefix . 'git submodule update --init --recursive 2>&1'; $final .= $command1 . "\n\n"; $returnCode = false;