Skip to content

Commit 8239cb5

Browse files
committed
Checks if given directory is a Git repository
1 parent 5cdfc33 commit 8239cb5

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/Commands/TreeCommand.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Stolt\LeanPackage\Commands;
66

7+
use Stolt\LeanPackage\Exceptions\GitHeadNotAvailable;
78
use Stolt\LeanPackage\Tree;
89
use Symfony\Component\Console\Command\Command;
910
use Symfony\Component\Console\Input\InputArgument;
@@ -80,14 +81,25 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8081
$verboseOutput = '+ Showing flat structure of dist package.';
8182
$output->writeln($verboseOutput, OutputInterface::VERBOSITY_VERBOSE);
8283

83-
$output->writeln('Package: <info>' . $this->getPackageName() . '</info>');
84-
$output->write($this->tree->getTreeForDistPackage());
84+
try {
85+
$treeToDisplay = $this->tree->getTreeForDistPackage($this->directoryToOperateOn);
86+
87+
$output->writeln('Package: <info>' . $this->getPackageName() . '</info>');
88+
$output->write($treeToDisplay);
89+
} catch (GitHeadNotAvailable $e) {
90+
$output->writeln('Directory <info>' . $this->directoryToOperateOn . '</info> has no Git Head.');
91+
return Command::FAILURE;
92+
}
8593

8694
return Command::SUCCESS;
8795
}
8896

8997
protected function getPackageName(): string
9098
{
99+
if (!\file_exists($this->directoryToOperateOn . DIRECTORY_SEPARATOR . 'composer.json')) {
100+
return 'unknown/unknown';
101+
}
102+
91103
$composerContentAsJson = \json_decode(
92104
\file_get_contents($this->directoryToOperateOn . DIRECTORY_SEPARATOR . 'composer.json'),
93105
true

src/Tree.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,10 @@ public function getTreeForSrc(string $directory): string
3232
* @throws GitHeadNotAvailable
3333
* @throws GitNotAvailable
3434
*/
35-
public function getTreeForDistPackage(): string
35+
public function getTreeForDistPackage(string $directory): string
3636
{
37+
\chdir($directory);
38+
3739
$this->archive->createArchive();
3840
$temporaryDirectory = \sys_get_temp_dir() . '/dist-release';
3941

0 commit comments

Comments
 (0)