Skip to content

Commit 0899167

Browse files
committed
Handle dev version of drupal/core, throw exception on non-zero exit codes (drupal-composer#41)
1 parent ad5fb54 commit 0899167

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

.travis.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ php:
66

77
sudo: false
88

9+
git:
10+
depth: 10000
11+
912
before_install:
1013
- phpenv config-rm xdebug.ini
1114
- composer --verbose self-update

src/Handler.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,13 @@ public function downloadScaffold() {
109109
$dispatcher = new EventDispatcher($this->composer, $this->io);
110110
$dispatcher->dispatch(self::PRE_DRUPAL_SCAFFOLD_CMD);
111111

112+
$version = $drupalCorePackage->getPrettyVersion();
113+
if ($drupalCorePackage->getStability() == 'dev' && substr($version, -4) == '-dev') {
114+
$version = substr($version, 0, -4);
115+
}
116+
112117
$fetcher = new FileFetcher(new RemoteFilesystem($this->io), $options['source'], $files);
113-
$fetcher->fetch($drupalCorePackage->getPrettyVersion(), $webroot);
118+
$fetcher->fetch($version, $webroot);
114119

115120
// Call post-scaffold scripts.
116121
$dispatcher->dispatch(self::POST_DRUPAL_SCAFFOLD_CMD);

tests/PluginTest.php

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,17 @@ public function testComposerInstallAndUpdate() {
7676
$this->composer('drupal-scaffold');
7777
$this->assertFileExists($exampleScaffoldFile, 'Scaffold file should be installed by "drupal-scaffold" command.');
7878

79-
// We touch a scaffold file, so we can check the file was modified after
80-
// the scaffold update.
81-
touch($exampleScaffoldFile);
82-
$mtime_touched = filemtime($exampleScaffoldFile);
83-
// Requiring a newer version triggers "composer update"
84-
$this->composer('require drupal/core:"8.0.1"');
85-
clearstatcache();
86-
$mtime_after = filemtime($exampleScaffoldFile);
87-
$this->assertNotEquals($mtime_after, $mtime_touched, 'Scaffold file was modified by composer update.');
79+
foreach (['8.0.1', '8.1.x-dev'] as $version) {
80+
// We touch a scaffold file, so we can check the file was modified after
81+
// the scaffold update.
82+
touch($exampleScaffoldFile);
83+
$mtime_touched = filemtime($exampleScaffoldFile);
84+
// Requiring a newer version triggers "composer update"
85+
$this->composer('require --update-with-dependencies drupal/core:"' . $version .'"');
86+
clearstatcache();
87+
$mtime_after = filemtime($exampleScaffoldFile);
88+
$this->assertNotEquals($mtime_after, $mtime_touched, 'Scaffold file was modified by composer update. (' . $version . ')');
89+
}
8890

8991
// We touch a scaffold file, so we can check the file was modified after
9092
// the custom commandscaffold update.
@@ -149,7 +151,10 @@ protected function composerJSONDefaults() {
149151
*/
150152
protected function composer($command) {
151153
chdir($this->tmpDir);
152-
passthru(escapeshellcmd($this->rootDir . '/vendor/bin/composer ' . $command));
154+
passthru(escapeshellcmd($this->rootDir . '/vendor/bin/composer ' . $command), $exit_code);
155+
if ($exit_code !== 0) {
156+
throw new \Exception('Composer returned a non-zero exit code');
157+
}
153158
}
154159

155160
/**
@@ -160,7 +165,10 @@ protected function composer($command) {
160165
*/
161166
protected function git($command) {
162167
chdir($this->rootDir);
163-
passthru(escapeshellcmd('git ' . $command));
168+
passthru(escapeshellcmd('git ' . $command), $exit_code);
169+
if ($exit_code !== 0) {
170+
throw new \Exception('Git returned a non-zero exit code');
171+
}
164172
}
165173

166174
/**

0 commit comments

Comments
 (0)