Search code examples
patch

Why is this patch failing


It's a very simple patch...

  • I've tried dos2unix on both files.
  • I've tried the --ignore-whitespace option.
  • 'file' command returns that both ASCII text.
  • I removed all whitespace at the end of the patch file, but I also tried with 1 and 2 empty lines at the end.

I'm applying the patch via composer and this is important because I need to be able to deploy the patch through CI/CD.

I am using cweagans/[email protected] package. I tried upgrading to 2.x-beta and encountered the same issues.

To rule out syntax issues, I tried applying the patch via PHPStorm Git utility and this worked without issue.

If use --verbose with the composer command, I can see the command it is using to apply the patch. When I try to apply the patch directly with this command I get the same error, shown here:

patch '-p1' --verbose --ignore-whitespace --no-backup-if-mismatch -d 'web/modules/contrib/activitytracking' < /var/www/html/patches/activitytracking-2023-09-14.patch
Hmm...  Looks like a unified diff to me...
The text leading up to this was:
--------------------------
|diff --git a/activity_tracking.info.yml b/activity_tracking.info.yml
|index bb406b3..ca61b8f 100644
|--- a/activity_tracking.info.yml
|+++ b/activity_tracking.info.yml
--------------------------
patching file activity_tracking.info.yml
Using Plan A...
Hunk #1 FAILED at 5.
1 out of 1 hunk FAILED -- saving rejects to file activity_tracking.info.yml.rej
done

Patch:

diff --git a/activity_tracking.info.yml b/activity_tracking.info.yml
index bb406b3..ca61b8f 100644
--- a/activity_tracking.info.yml
+++ b/activity_tracking.info.yml
@@ -5,5 +5,4 @@ description: 'Allow system to track each activity performed by user.'
 dependencies:
   - drupal:user
   - drupal:system (>=8.1.0)
-core: '8.x'
-core_version_requirement: ^8 || ^9
+core_version_requirement: ^8 || ^9 || ^10

Target:

name: Activity Tracking
type: module
description: 'Allow system to track each activity performed by user.'
# core: 8.x
dependencies:
  - drupal:user
  - drupal:system (>=8.1.0)
core: '8.x'
core_version_requirement: ^8 || ^9

Solution

  • OK, I've identified the issue.

    The file that's failing, in your zip, has additional lines after the "core_version_requirement". That's the issue. If there are lines following the change, then the patch must include those lines to allow the algorithm to resync, otherwise it's considered a failure. The patch that you posted above works, because there are no lines after the "core_version_requirement".

    That's why it's so important to post the exact files that are failing.

    So, if your patch is:

    diff --git a/activity_tracking.info.yml b/activity_tracking.info.yml
    index bb406b3..023b63d 100644
    --- a/activity_tracking.info.yml
    +++ b/activity_tracking.info.yml
    @@ -6,6 +6,6 @@
       - drupal:user
       - drupal:system (>=8.1.0)
     core: '8.x'
    -core_version_requirement: ^8 || ^9
    +core_version_requirement: ^8 || ^9 || ^10
     
     # Information added by Drupal.org packaging script on 2022-03-28
    

    then it works.