Skip to content

Commit 976d23e

Browse files
committed
Fix output enclosure in dist command
1 parent 2a1414c commit 976d23e

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

src/Phug/Split/Command/Dist.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ protected function distribute(Split $cli): bool
7575
return $cli->error('Unable to create output directory.');
7676
}
7777

78-
if (!preg_match('/^\* (.+)$/m', $this->git('branch'), $branch)) {
78+
if (!preg_match('/^\* (.+)$/m', $this->git('branch', [], '2>&1'), $branch)) {
7979
return $cli->error('You must be on a branch in a git repository to run this command.');
8080
}
8181

8282
$branch = $branch[1];
8383

8484
if (substr($branch, 0, 18) === '(HEAD detached at ') {
85-
$branch = trim(explode("\n", $this->git('describe --contains --all HEAD'))[0]);
85+
$branch = trim(explode("\n", $this->git('describe --contains --all HEAD', [], '2>&1'))[0]);
8686
}
8787

8888
foreach ($this->getPackages() as $package) {
@@ -121,7 +121,7 @@ protected function distributePackage(Split $cli, array $package, string $branch)
121121
}
122122

123123
$cli->gray();
124-
$this->git("clone $url $directory");
124+
$cli->write($this->git("clone $url $directory", [], '2>&1'));
125125
$cli->discolor();
126126

127127
$cli->chdir($directory);

tests/Phug/Command/DistTest.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function testRun()
6969
shell_exec('git commit --file=message.txt 2>&1');
7070
preg_match('/^commit (\S+)/', shell_exec('git log -n 1'), $match);
7171
$hash2 = $match[1];
72-
shell_exec("git checkout $hash2");
72+
shell_exec("git checkout $hash2 2>&1");
7373

7474
chdir($directory1);
7575

@@ -97,7 +97,9 @@ public function testRun()
9797
'vendor/package',
9898
'#[1;35mBuild vendor/sub-package',
9999
"#[0m#[1;32mgit clone $directory2 {$path}dist/vendor/sub-package",
100-
"#[0m#[1;30m#[0m#[1;34mcd {$path}dist/vendor/sub-package",
100+
"#[0m#[1;30mCloning into '{$path}dist/vendor/sub-package'...",
101+
'done.',
102+
"#[0m#[1;34mcd {$path}dist/vendor/sub-package",
101103
'#[0m#[1;32mgit checkout master',
102104
"#[0m#[1;30m#[0m#[1;35mBuild distributed in {$path}dist",
103105
'#[0m',
@@ -115,20 +117,29 @@ public function testRun()
115117
*/
116118
public function testErrors()
117119
{
120+
$cwd = getcwd();
118121
$cli = new Split();
119122
$cli->setEscapeCharacter('#');
120123

121124
$dist = new Dist();
122125

126+
$directory = sys_get_temp_dir().'/split-test-'.mt_rand(0, 9999999);
127+
FileSystem::createDir($directory);
128+
$directory = realpath($directory);
129+
chdir($directory);
130+
123131
ob_start();
124132
$return = $dist->run($cli);
125133
$output = ob_get_contents();
126134
ob_end_clean();
127135

136+
@shell_exec('rm -rf ' . escapeshellarg($directory) . ' 2>&1');
137+
file_exists($directory) && @shell_exec('rmdir /S /Q ' . escapeshellarg($directory) . ' 2>&1');
138+
@FileSystem::delete($directory);
139+
128140
$this->assertSame("#[0;31mRoot project directory should contains a composer.json file.\n#[0m", $output);
129141
$this->assertFalse($return);
130142

131-
$cwd = getcwd();
132143
$dist = new Dist();
133144

134145
$directory = sys_get_temp_dir().'/split-test-'.mt_rand(0, 9999999);

0 commit comments

Comments
 (0)