Skip to content

Commit fffd7e7

Browse files
committed
Handles differing Unix tree command behaviour
1 parent 5e073c6 commit fffd7e7

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

src/Helpers/Str.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,13 @@ public function isWindows($os = PHP_OS): bool
1919

2020
return true;
2121
}
22+
23+
public function isMacOs($os = PHP_OS): bool
24+
{
25+
if (\strtoupper(\substr($os, 0, 3)) !== 'DAR') {
26+
return false;
27+
}
28+
29+
return true;
30+
}
2231
}

src/Tree.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@ public function __construct(Archive $archive)
2929

3030
public function getTreeForSrc(string $directory): string
3131
{
32-
\exec(
33-
'tree -aL 1 --dirsfirst ' . \escapeshellarg($directory) . ' --gitignore -I .git 2>&1',
34-
$output
35-
);
32+
$command = 'tree -aL 1 --dirsfirst ' . \escapeshellarg($directory) . ' -I .git 2>&1';
33+
34+
if ((new OsHelper())->isMacOs()) {
35+
$command = 'tree -aL 1 --dirsfirst ' . \escapeshellarg($directory) . ' --gitignore -I .git 2>&1';
36+
}
37+
38+
\exec($command, $output);
3639

3740
$output[0] = '.';
3841

@@ -43,10 +46,13 @@ public function getTreeForDistPackage(string $directory): string
4346
{
4447
$this->archive->createArchive();
4548

46-
\exec(
47-
'tar --list --exclude="*/*" --file ' . \escapeshellarg($this->archive->getFilename()) . ' | tree -aL 1 --dirsfirst --fromfile . 2>&1',
48-
$output
49-
);
49+
$command = 'tar --list --exclude="*/*" --file ' . \escapeshellarg($this->archive->getFilename()) . ' | tree -aL 1 --dirsfirst --fromfile . 2>&1';
50+
51+
if ((new OsHelper())->isMacOs()) {
52+
$command = 'tar --list --file ' . \escapeshellarg($this->archive->getFilename()) . ' | tree -aL 1 --dirsfirst --fromfile . 2>&1';
53+
}
54+
55+
\exec($command, $output);
5056

5157
$this->archive->removeArchive();
5258

0 commit comments

Comments
 (0)