From acbf9fab42274ab9b2dd49925689544c1c4be0e4 Mon Sep 17 00:00:00 2001 From: Steven Rombauts Date: Tue, 12 Dec 2017 12:14:08 +0000 Subject: [PATCH] #36: Fix --clone option default value The InputOption::VALUE_OPTIONAL option mode will always return null if you don't set a default value, but returning any other value makes it impossible to correctly determine whether the flag was set or not. Solution is to rely on $input->hasParameterOption() instead. See: https://github.com/symfony/symfony/issues/11572\#issuecomment-197929086 --- src/Joomlatools/Console/Command/Site/Create.php | 7 +++++-- src/Joomlatools/Console/Command/Site/Download.php | 9 +++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Joomlatools/Console/Command/Site/Create.php b/src/Joomlatools/Console/Command/Site/Create.php index 08853cee..13222249 100644 --- a/src/Joomlatools/Console/Command/Site/Create.php +++ b/src/Joomlatools/Console/Command/Site/Create.php @@ -201,10 +201,13 @@ public function download(InputInterface $input, OutputInterface $output) 'site' => $this->site, '--release' => $input->getOption('release'), '--clear-cache' => $input->getOption('clear-cache'), - '--www' => $this->www, - '--clone' => $input->getOption('clone') + '--www' => $this->www ); + if ($input->hasParameterOption('--clone')) { + $arguments['--clone'] = $input->getOption('clone'); + } + $repo = $input->getOption('repo'); if (!empty($repo)) { $arguments['--repo'] = $repo; diff --git a/src/Joomlatools/Console/Command/Site/Download.php b/src/Joomlatools/Console/Command/Site/Download.php index f4d535eb..b902f3a0 100644 --- a/src/Joomlatools/Console/Command/Site/Download.php +++ b/src/Joomlatools/Console/Command/Site/Download.php @@ -76,8 +76,9 @@ protected function configure() 'clone', null, InputOption::VALUE_OPTIONAL, - 'Clone the Git repository instead of creating a copy in the target directory. Use --clone=shallow for a shallow clone or leave empty.' - ) + 'Clone the Git repository instead of creating a copy in the target directory. Use --clone=shallow for a shallow clone or leave empty.', + true + ); ; } @@ -114,7 +115,7 @@ protected function execute(InputInterface $input, OutputInterface $output) return; } - if ($input->getOption('clone')) { + if ($input->hasParameterOption('--clone')) { $this->_setupClone(); } else $this->_setupCopy(); @@ -333,7 +334,7 @@ protected function _clone($directory, $tag = false) } $command = sprintf("git clone %s --recursive %s %s", $args, escapeshellarg($repository), escapeshellarg($directory)); - + exec($command, $result, $exit_code); if ($exit_code > 0) {