Skip to content
New issue

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

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

Already on GitHub? # to your account

What would be a good flow to modify existing patches? #22

Open
ArtemGoutsoul opened this issue Apr 17, 2024 · 1 comment
Open

What would be a good flow to modify existing patches? #22

ArtemGoutsoul opened this issue Apr 17, 2024 · 1 comment

Comments

@ArtemGoutsoul
Copy link

Brainstorming a possible flow:

  • backup modified files to tmp
  • remove a patch (I guess - remove it from composer.json, run composer install)
  • backup unmodified files as .old
  • copy modified files from tmp
  • modify as needed
  • vendor/bin/vendor-patches generate
  • profit

Option 1

  • if it seems correct, add the above flow description to the readme

Option 2 (Ideal)

  • on composer install, automatically copy unmodified files to .old before patching)
  • this way the above flow would be simplified to:
    • modify files
    • vendor/bin/vendor-patches generate
@ArtemGoutsoul
Copy link
Author

Wrote and tested a little bash script to generate .old files.
The script has to live in the patches folder for convenience.
It will iterate through all patch files create original files.
This way one can modify the sources again and and run vendor/bin/vendor-patches generate

#!/bin/bash

script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
patch_dir="$script_dir"
vendor_dir="$script_dir/../vendor"

for patch_file in "$patch_dir"/*.patch; do
    echo ""
    echo "patch: $patch_file"

    # Extract the first two components of the patch file name for the base directory
    target_folder=$(basename "$patch_file" | cut -d'-' -f1,2 | tr '-' '/')

    # Read the new file path from the patch file's '+++' line and extract the path part only
    target_file_path_from_patch=$(grep '^\+\+\+' "$patch_file" | head -n 1 | sed -e 's/^\+\+\+ \(.*\)/\1/' -e 's/^\.\.\///')
    full_target_path="$vendor_dir/$target_folder/$target_file_path_from_patch"
    backup_file_path="${full_target_path}.old"

    # Apply the reverse patch to the target file and save as .old
    if [ -f "$full_target_path" ]; then
        cp "$full_target_path" "$backup_file_path"
        patch "$backup_file_path" "$patch_file" --reverse
    else
        echo "Target file does not exist:"
        echo " - $full_target_path"
    fi
done

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant