@@ -444,7 +444,7 @@ public function updateCommitStatus(string $repositoryName, string $commitHash, s
444444 /**
445445 * Generates a clone command using app access token
446446 */
447- public function generateCloneCommand (string $ owner , string $ repositoryName , string $ branchName , string $ directory , string $ rootDirectory ): string
447+ public function generateCloneCommand (string $ owner , string $ repositoryName , string $ branchName , string $ directory , string $ rootDirectory, string $ commitHash = null ): string
448448 {
449449 if (empty ($ rootDirectory )) {
450450 $ rootDirectory = '* ' ;
@@ -459,6 +459,9 @@ public function generateCloneCommand(string $owner, string $repositoryName, stri
459459 $ directory = escapeshellarg ($ directory );
460460 $ rootDirectory = escapeshellarg ($ rootDirectory );
461461 $ branchName = escapeshellarg ($ branchName );
462+ if (!empty ($ commitHash )) {
463+ $ commitHash = escapeshellarg ($ commitHash );
464+ }
462465
463466 $ commands = [
464467 "mkdir -p {$ directory }" ,
@@ -468,9 +471,14 @@ public function generateCloneCommand(string $owner, string $repositoryName, stri
468471 "git remote add origin {$ cloneUrl }" ,
469472 "git config core.sparseCheckout true " ,
470473 "echo {$ rootDirectory } >> .git/info/sparse-checkout " ,
471- "if git ls-remote --exit-code --heads origin {$ branchName }; then git pull origin {$ branchName } && git checkout {$ branchName }; else git checkout -b {$ branchName }; fi "
472474 ];
473475
476+ if (empty ($ commitHash )) {
477+ $ commands [] = "if git ls-remote --exit-code --heads origin {$ branchName }; then git pull origin {$ branchName } && git checkout {$ branchName }; else git checkout -b {$ branchName }; fi " ;
478+ } else {
479+ $ commands [] = "git pull origin {$ commitHash }" ;
480+ }
481+
474482 $ fullCommand = implode (" && " , $ commands );
475483
476484 return $ fullCommand ;
0 commit comments