Fix git apply empty result using patch
Submitted by clemens on Fri, 2015/02/20 - 2:55pm
When applying a patch using git it sometimes fails. Then fallback on the patch command.
Download the patch file
$ wget https://www.drupal.org/files/issues/rest-collection-2100637-oos.94.patch
Compare for
$ git apply rest-collection-2100637-oos.94.patch
error: patch failed: core/modules/hal/src/Tests/FileNormalizeTest.php:39
error: core/modules/hal/src/Tests/FileNormalizeTest.php: patch does not apply
error: patch failed: core/modules/hal/src/Tests/NormalizeTest.php:7
error: core/modules/hal/src/Tests/NormalizeTest.php: patch does not apply
error: patch failed: core/modules/hal/src/Tests/NormalizerTestBase.php:134
error: core/modules/hal/src/Tests/NormalizerTestBase.php: patch does not apply
error: patch failed: core/modules/rest/rest.services.yml:15
error: core/modules/rest/rest.services.yml: patch does not apply
error: patch failed: core/modules/rest/tests/modules/rest_test_views/test_views/views.view.test_serializer_display_entity.yml:43
error: core/modules/rest/tests/modules/rest_test_views/test_views/views.view.test_serializer_display_entity.yml: patch does not apply
error: patch failed: core/modules/rest/tests/modules/rest_test_views/test_views/views.view.test_serializer_display_field.yml:95
error: core/modules/rest/tests/modules/rest_test_views/test_views/views.view.test_serializer_display_field.yml: patch does not apply
which leaves one puzzled. Nothing left to tackle. Then use
$ patch --strip=1 --fuzz 100 < rest-collection-2100637-oos.94.patch
# Using short options: $ patch -p1 -F100
patching file core/modules/hal/hal.services.yml
patching file core/modules/hal/src/Normalizer/CollectionNormalizer.php
patching file core/modules/hal/src/Tests/FileNormalizeTest.php
Hunk #2 FAILED at 40.
1 out of 2 hunks FAILED -- saving rejects to file core/modules/hal/src/Tests/FileNormalizeTest.php.rej
patching file core/modules/hal/src/Tests/NormalizeTest.php
Hunk #1 succeeded at 9 with fuzz 2 (offset 2 lines).
patching file core/modules/hal/src/Tests/NormalizerTestBase.php
Hunk #2 FAILED at 135.
1 out of 2 hunks FAILED -- saving rejects to file core/modules/hal/src/Tests/NormalizerTestBase.php.rej
patching file core/modules/hal/tests/src/Unit/CollectionNormalizerTest.php
patching file core/modules/rest/rest.services.yml
Hunk #1 FAILED at 15.
1 out of 1 hunk FAILED -- saving rejects to file core/modules/rest/rest.services.yml.rej
patching file core/modules/rest/src/LinkManager/CollectionLinkManager.php
patching file core/modules/rest/src/LinkManager/CollectionLinkManagerInterface.php
patching file core/modules/rest/src/LinkManager/LinkManager.php
patching file core/modules/rest/src/LinkManager/LinkManagerInterface.php
patching file core/modules/rest/src/Plugin/views/display/RestExport.php
patching file core/modules/rest/src/Plugin/views/style/Serializer.php
patching file core/modules/rest/src/Tests/Views/StyleSerializerTest.php
patching file core/modules/rest/tests/modules/rest_test_views/test_views/views.view.test_serializer_display_entity.yml
Hunk #1 succeeded at 43 with fuzz 3.
patching file core/modules/rest/tests/modules/rest_test_views/test_views/views.view.test_serializer_display_field.yml
Hunk #1 succeeded at 95 with fuzz 3.
patching file core/modules/serialization/src/Collection.php
patching file core/modules/serialization/tests/src/Unit/CollectionTest.php
$ git status
...
modified: core/modules/hal/hal.services.yml
modified: core/modules/hal/src/Tests/FileNormalizeTest.php
modified: core/modules/hal/src/Tests/NormalizeTest.php
modified: core/modules/hal/src/Tests/NormalizerTestBase.php
modified: core/modules/rest/src/LinkManager/LinkManager.php
modified: core/modules/rest/src/LinkManager/LinkManagerInterface.php
modified: core/modules/rest/src/Plugin/views/display/RestExport.php
modified: core/modules/rest/src/Plugin/views/style/Serializer.php
modified: core/modules/rest/src/Tests/Views/StyleSerializerTest.php
modified: core/modules/rest/tests/modules/rest_test_views/test_views/views.view.test_serializer_display_entity.yml
modified: core/modules/rest/tests/modules/rest_test_views/test_views/views.view.test_serializer_display_field.yml
...
Untracked files:
(use "git add <file>..." to include in what will be committed)
core/modules/hal/src/Normalizer/CollectionNormalizer.php
core/modules/hal/src/Tests/FileNormalizeTest.php.orig
core/modules/hal/src/Tests/FileNormalizeTest.php.rej
core/modules/hal/src/Tests/NormalizeTest.php.orig
core/modules/hal/src/Tests/NormalizerTestBase.php.orig
core/modules/hal/src/Tests/NormalizerTestBase.php.rej
core/modules/hal/tests/src/Unit/CollectionNormalizerTest.php
core/modules/rest/rest.services.yml.orig
core/modules/rest/rest.services.yml.rej
core/modules/rest/src/LinkManager/CollectionLinkManager.php
core/modules/rest/src/LinkManager/CollectionLinkManagerInterface.php
core/modules/rest/tests/modules/rest_test_views/test_views/views.view.test_serializer_display_entity.yml.orig
core/modules/rest/tests/modules/rest_test_views/test_views/views.view.test_serializer_display_field.yml.orig
core/modules/serialization/src/Collection.php
core/modules/serialization/tests/src/Unit/CollectionTest.php
which leaves some hints to fix. Edit the code by using the .rej files.
To get rid of the mess just run
$ git reset --hard
$ git clean --force -d core
# Using short options: $ git clean -fd