vendorファイルの一部に不具合があり、パッチを当てることにしました。
しかし、実行してみるとエラーが発生してしまい、パッチを当てることができません。
Could not apply patch! Skipping. The error was: Cannot apply patch
次のような手順で行いました。
composer-patchesをインストール
composer require cweagans/composer-patches
パッチファイルの保存先フォルダ
patches_composer
を作成編集対象ファイル(Response.php)を .orig としてコピー
cp vendor/inertiajs/inertia-laravel/src/Response.php vendor/inertiajs/inertia-laravel/src/Response.php.orig
編集対象ファイル(Response.php)を編集(修正)
差分ファイルの作成
diff -u vendor/inertiajs/inertia-laravel/src/Response.php.orig vendor/inertiajs/inertia-laravel/src/Response.php > patches_composer/inertia-laravel-response.patch
編集対象ファイル(Response.php) とオリジナル(Response.php.orig)を比較して、
差分ファイル(patches_composer/inertia-laravel-response.patch)を出力composer.json ファイルにパッチの情報を追加
"extra": {
"patches": {
"inertiajs/inertia-laravel": {
"twice url": "patches_composer/inertia-laravel-response.patch"
}
}
},
ちなみに差分ファイルの中身は次のようになっています
※先頭行の Response.php.orig を Response.php に変更
--- vendor/inertiajs/inertia-laravel/src/Response.php 2023-05-26 02:25:36.821932134 +0900
+++ vendor/inertiajs/inertia-laravel/src/Response.php 2023-05-26 02:25:47.802044249 +0900
@@ -91,7 +91,7 @@
$props = ($only && $request->header('X-Inertia-Partial-Component') === $this->component)
? Arr::only($this->props, $only)
: array_filter($this->props, static function ($prop) {
- return ! ($prop instanceof LazyProp);
+ return !($prop instanceof LazyProp);
});
$props = $this->resolvePropertyInstances($props, $request);
@@ -99,7 +99,7 @@
$page = [
'component' => $this->component,
'props' => $props,
- 'url' => $request->getBaseUrl().$request->getRequestUri(),
+ 'url' => $request->getRequestUri(),
'version' => $this->version,
];
エラー
しかしながら、composer install, composer update を実行すると次のようなエラーが発生します。
- Applying patches for inertiajs/inertia-laravel
patches_composer/inertia-laravel-response.patch (twice url)
Could not apply patch! Skipping. The error was: Cannot apply patch patches_composer/inertia-laravel-response.patch
エラーの詳細がわからないため、どのように対応すればよいのかがわかりません。
上記の手順の中で、誤った部分があるでしょうか?
よろしくお願いします。
【追記】
パッチファイルの先頭が「更新されるファイル」のようなので下記のように変更しました。
--- vendor/inertiajs/inertia-laravel/src/Rsponse.php
composer install -vvv
で処理の詳細を出力。
Dependency resolution completed in 0.000 seconds
Package operations: 1 install, 0 updates, 0 removals
Installs: inertiajs/inertia-laravel:v0.6.9
Reading /home/my_name/.cache/composer/files/inertiajs/inertia-laravel/09ba8e3a83de8dc1b2da392e03f79f9e6a30867a.zip from cache
- Loading inertiajs/inertia-laravel (v0.6.9) from cache
> pre-package-install: cweagans\Composer\Patches->gatherPatches
Gathering patches for root package.
Gathering patches for dependencies. This might take a minute.
Found 1 patches for inertiajs/inertia-laravel.
- Installing inertiajs/inertia-laravel (v0.6.9): Extracting archive
Executing async command (CWD): '/usr/bin/unzip' -qq '/home/my_name/my_project/vendor/composer/tmp-7ca65e1c011ddf0b2205cb6db25fb1ba' -d '/home/my_name/my_project/vendor/composer/4b699ac1'
Executing async command (CWD): rm -rf '/home/my_name/my_project/vendor/composer/4b699ac1'
> post-package-install: cweagans\Composer\Patches->postInstall
- Applying patches for inertiajs/inertia-laravel
patches_composer/inertia-laravel-response.patch (twice url)
patch '-p1' --no-backup-if-mismatch -d '/home/my_name/my_project/vendor/inertiajs/inertia-laravel' < '/home/my_name/my_project/patches_composer/inertia-laravel-response.patch'
Executing command (CWD): patch '-p1' --no-backup-if-mismatch -d '/home/my_name/my_project/vendor/inertiajs/inertia-laravel' < '/home/my_name/my_project/patches_composer/inertia-laravel-response.patch'
can't find file to patch at input line 3
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|--- vendor/inertiajs/inertia-laravel/src/Response.php 2023-05-26 07:43:20.246192609 +0900
|+++ vendor/inertiajs/inertia-laravel/src/Response.php 2023-05-26 07:41:02.059394179 +0900
--------------------------
File to patch:
Skip this patch? [y]
Skipping patch.
1 out of 1 hunk ignored
patch '-p0' --no-backup-if-mismatch -d '/home/my_name/my_project/vendor/inertiajs/inertia-laravel' < '/home/my_name/my_project/patches_composer/inertia-laravel-response.patch'
Executing command (CWD): patch '-p0' --no-backup-if-mismatch -d '/home/my_name/my_project/vendor/inertiajs/inertia-laravel' < '/home/my_name/my_project/patches_composer/inertia-laravel-response.patch'
can't find file to patch at input line 3
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|--- vendor/inertiajs/inertia-laravel/src/Response.php 2023-05-26 07:43:20.246192609 +0900
|+++ vendor/inertiajs/inertia-laravel/src/Response.php 2023-05-26 07:41:02.059394179 +0900
--------------------------
File to patch:
Skip this patch? [y]
Skipping patch.
1 out of 1 hunk ignored
patch '-p2' --no-backup-if-mismatch -d '/home/my_name/my_project/vendor/inertiajs/inertia-laravel' < '/home/my_name/my_project/patches_composer/inertia-laravel-response.patch'
Executing command (CWD): patch '-p2' --no-backup-if-mismatch -d '/home/my_name/my_project/vendor/inertiajs/inertia-laravel' < '/home/my_name/my_project/patches_composer/inertia-laravel-response.patch'
can't find file to patch at input line 3
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|--- vendor/inertiajs/inertia-laravel/src/Response.php 2023-05-26 07:43:20.246192609 +0900
|+++ vendor/inertiajs/inertia-laravel/src/Response.php 2023-05-26 07:41:02.059394179 +0900
--------------------------
File to patch:
Skip this patch? [y]
Skipping patch.
1 out of 1 hunk ignored
patch '-p4' --no-backup-if-mismatch -d '/home/my_name/my_project/vendor/inertiajs/inertia-laravel' < '/home/my_name/my_project/patches_composer/inertia-laravel-response.patch'
Executing command (CWD): patch '-p4' --no-backup-if-mismatch -d '/home/my_name/my_project/vendor/inertiajs/inertia-laravel' < '/home/my_name/my_project/patches_composer/inertia-laravel-response.patch'
can't find file to patch at input line 3
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|--- vendor/inertiajs/inertia-laravel/src/Response.php 2023-05-26 07:43:20.246192609 +0900
|+++ vendor/inertiajs/inertia-laravel/src/Response.php 2023-05-26 07:41:02.059394179 +0900
--------------------------
File to patch:
Skip this patch? [y]
Skipping patch.
1 out of 1 hunk ignored
Could not apply patch! Skipping. The error was: Cannot apply patch patches_composer/inertia-laravel-response.patch
上記の動作を見ると、inertiajs/inertia-laravel/
がアップデートされて、その後にパッチを当てているように見えます。
can't find file to patch at input line 3
については無視しても良いようです。