evo-patch-generate-apply
Generates git-compatible unified diff patches from original and modified file contents, writes them to numbered patch files, and applies them to the repository using git apply or GNU patch. Use when y
SKILL.mdtasks-evolved/fix-build-agentops/environment/skills/evo-patch-generate-apply/SKILL.md
GitHubPatch Generate & Apply Skill
Generates and applies unified diff patches for code fixes.
When to Use
- You need to generate a patch file from code changes
- You need to apply a .diff/.patch file to a repository
- Automating code fixes via the diff/patch workflow
Workflow
- Generate diff using
generate_unified_diff()with a/b prefixes - Handle EOF using
handle_no_newline_at_eof()for POSIX compliance - Write patch using
write_patch_file()to create patch_N.diff - Apply patch using
apply_patch()with git apply and fallbacks - Validate using
validate_patch_applied()to confirm changes - Batch apply using
apply_all_patches()for multiple patches
Key Functions
All functions are in scripts/patch.py:
generate_unified_diff(original, modified, file_path)- Creates git-compatible unified diffhandle_no_newline_at_eof(diff_lines)- Adds missing EOF newline markerswrite_patch_file(diff_content, output_dir, index)- Writes patch_N.diffapply_patch(patch_path, target_dir)- Applies via git apply with fallbacksvalidate_patch_applied(file_path, expected_content)- Confirms patch workedapply_all_patches(patch_dir, target_dir)- Applies all patches in order
Important Notes
- Use splitlines(keepends=True) to preserve trailing newlines
- Always add a/ and b/ prefixes for git apply compatibility
- Handle "No newline at end of file" marker manually
- git apply uses -p1 by default to strip a/ b/ prefixes
- Use --3way flag as fallback for context mismatches
Reference
See references/domain_reference.md for detailed domain knowledge.