From ca6890a5c3558170fefbac15e53a877ac024f968 Mon Sep 17 00:00:00 2001 From: Dan Cryer Date: Mon, 5 May 2014 21:03:44 +0100 Subject: [PATCH] Implement clone_depth setting in build_settings, to allow shallow clones. Fixes #391 --- PHPCI/Model/Build/RemoteGitBuild.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/PHPCI/Model/Build/RemoteGitBuild.php b/PHPCI/Model/Build/RemoteGitBuild.php index 144f69f6..9c7c6a26 100644 --- a/PHPCI/Model/Build/RemoteGitBuild.php +++ b/PHPCI/Model/Build/RemoteGitBuild.php @@ -54,7 +54,15 @@ class RemoteGitBuild extends Build */ protected function cloneByHttp(Builder $builder, $cloneTo) { - $cmd = 'git clone -b %s %s "%s"'; + $cmd = 'git clone '; + + $depth = $builder->getConfig('clone_depth'); + + if (!is_null($depth)) { + $cmd .= ' --depth ' . intval($depth) . ' '; + } + + $cmd .= ' -b %s %s "%s"'; $success = $builder->executeCommand($cmd, $this->getBranch(), $this->getCloneUrl(), $cloneTo); if (!empty($commit) && $commit != 'Manual') { @@ -80,14 +88,20 @@ class RemoteGitBuild extends Build } // Do the git clone: - $cmd = 'git clone -b %s %s "%s"'; + $cmd = 'git clone '; + + $depth = $builder->getConfig('clone_depth'); + + if (!is_null($depth)) { + $cmd .= ' --depth ' . intval($depth) . ' '; + } + + $cmd .= ' -b %s %s "%s"'; if (!IS_WIN) { $cmd = 'export GIT_SSH="'.$gitSshWrapper.'" && ' . $cmd; } - var_dump($cmd); - $success = $builder->executeCommand($cmd, $this->getBranch(), $this->getCloneUrl(), $cloneTo); // Checkout a specific commit if we need to: