Skip to content

Commit

Permalink
Merge pull request #609 from cweagans/608-composer-no-cache
Browse files Browse the repository at this point in the history
Patching fails when --no-cache is passed
  • Loading branch information
cweagans authored Dec 26, 2024
2 parents c7d82a4 + 9a12eda commit 47ba085
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Downloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,16 @@ public function __construct(Composer $composer, IOInterface $io, array $disabled
$this->io = $io;
$this->disabledDownloaders = $disabledDownloaders;

$this->cacheDir = $composer->getConfig()->get('cache-dir') . '/patches';
// If --no-cache is passed to Composer, we need a different location to
// download patches to. When --no-cache is passed, $composer_cache is
// set to /dev/null.
$composer_cache = $composer->getConfig()->get('cache-dir');
if (!is_dir($composer_cache)) {
$composer_cache = sys_get_temp_dir();
}

// If the cache directory doesn't exist, create it.
$this->cacheDir = $composer_cache . '/patches';
if (!is_dir($this->cacheDir)) {
mkdir($this->cacheDir);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "cweagans/composer-patches-test-project",
"description": "Project for use in cweagans/composer-patches acceptance tests.",
"type": "project",
"license": "BSD-3-Clause",
"repositories": [
{
"type": "path",
"url": "../../../../"
}
],
"require": {
"cweagans/composer-patches": "*@dev",
"cweagans/composer-patches-testrepo": "~1.0"
},
"extra": {
"patches": {
"cweagans/composer-patches-testrepo": {
"Add a file": "https://patch-diff.githubusercontent.com/raw/cweagans/composer-patches-testrepo/pull/1.patch"
}
}
},
"config": {
"preferred-install": "source",
"allow-plugins": {
"cweagans/composer-patches": true
}
}
}
13 changes: 13 additions & 0 deletions tests/acceptance/ApplyGitPatchFromWebNoCacheCept.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

/**
* @var \Codeception\Scenario $scenario
*/

use cweagans\Composer\Tests\AcceptanceTester;

$I = new AcceptanceTester($scenario);
$I->wantTo('modify a package using a patch downloaded from the internet (with "composer --no-cache")');
$I->amInPath(codecept_data_dir('fixtures/apply-git-patch-from-web-no-cache'));
$I->runComposerCommand('install', ['-vvv', '--no-cache']);
$I->canSeeFileFound('./vendor/cweagans/composer-patches-testrepo/src/OneMoreTest.php');

0 comments on commit 47ba085

Please sign in to comment.