Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patching fails when --no-cache is passed #609

Merged
merged 1 commit into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');