Skip to content

Commit 7ecc0dd

Browse files
committed
Display executed SVN commands in real time, when verbose mode is enabled
1 parent 090bee3 commit 7ecc0dd

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
77
...
88

99
### Changed
10-
...
10+
- Show executed SVN commands in real time (when started; how long was executed) in verbose mode (the `-v` flag).
1111

1212
### Fixed
1313
...

src/SVNBuddy/Repository/Connector/Command.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,21 @@ private function _doRun($callback = null)
217217
$command_string = (string)$this;
218218

219219
try {
220-
$start = microtime(true);
221-
$process->mustRun($callback);
222-
223220
if ( $this->_io->isVerbose() ) {
221+
$this->_io->writeln('');
222+
$this->_io->write('<debug>[svn, ' . date('H:i:s') . '... ]: ' . $command_string . '</debug>');
223+
224+
$start = microtime(true);
225+
$process->mustRun($callback);
226+
224227
$runtime = sprintf('%01.2f', microtime(true) - $start);
225-
$this->_io->writeln(
226-
array('', '<debug>[svn, ' . round($runtime, 2) . 's]: ' . $command_string . '</debug>')
228+
$this->_io->write(
229+
"\033[2K\r" . '<debug>[svn, ' . round($runtime, 2) . 's]: ' . $command_string . '</debug>'
227230
);
231+
$this->_io->writeln('');
232+
}
233+
else {
234+
$process->mustRun($callback);
228235
}
229236

230237
$output = (string)$process->getOutput();

tests/SVNBuddy/Repository/Connector/CommandTest.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,24 @@ public function testVerboseOutput()
352352
$this->_io->isDebug()->willReturn(false)->shouldBeCalled();
353353
$this->_cacheManager->getCache(Argument::any())->shouldNotBeCalled();
354354

355-
$this->_io->writeln(Argument::that(function ($messages) {
356-
if ( count($messages) !== 2 || $messages[0] !== '' ) {
355+
$this->_io->writeln('')->shouldBeCalled();
356+
357+
$this->_io->write(Argument::that(function ($message) {
358+
if ( strpos($message, '[svn, ') === false ) {
357359
return false;
358360
}
359361

360-
return preg_replace('/\[svn, [\d.]+s\]/', '[svn, 0s]', $messages[1]) === '<debug>[svn, 0s]: svn log</debug>';
362+
// Before command runs.
363+
if ( preg_match('/^<debug>\[svn, \d+:\d+:\d+... \]: svn log<\/debug>$/', $message) ) {
364+
return true;
365+
}
366+
367+
// After command runs.
368+
if ( preg_match('/^' . "\033[2K\r" . '<debug>\[svn, [\d.]+s\]: svn log<\/debug>$/', $message) ) {
369+
return true;
370+
}
371+
372+
return false;
361373
}))->shouldBeCalled();
362374

363375
$this->_command->run();
@@ -425,7 +437,7 @@ public function testRunError()
425437
$this->_process->getErrorOutput()->willReturn('error output')->shouldBeCalled();
426438

427439
$this->_process->getOutput()->shouldNotBeCalled();
428-
$this->_io->isVerbose()->shouldNotBeCalled();
440+
$this->_io->isVerbose()->shouldBecalled();
429441
$this->_io->isDebug()->shouldNotBeCalled();
430442

431443
$this->_cacheManager->getCache(Argument::any())->shouldNotBeCalled();

0 commit comments

Comments
 (0)