Skip to content

Commit

Permalink
#36: Fix --clone option default value
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Steven Rombauts committed Dec 12, 2017
1 parent ad41c45 commit acbf9fa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/Joomlatools/Console/Command/Site/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions src/Joomlatools/Console/Command/Site/Download.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
;
}

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit acbf9fa

Please sign in to comment.