summaryrefslogtreecommitdiff
path: root/tests/patch
Commit message (Collapse)AuthorAgeFilesLines
* Merge pull request #5159 from pks-t/pks/patch-parse-old-missing-nlEdward Thomson2019-07-202-3/+33
|\ | | | | patch_parse: handle missing newline indicator in old file
| * patch_parse: ensure valid patch output with EOFNLErik Aigner2019-07-111-9/+15
| |
| * patch_parse: handle missing newline indicator in old filePatrick Steinhardt2019-07-112-0/+24
| | | | | | | | | | | | | | | | | | | | | | When either the old or new file contents have no newline at the end of the file, then git-diff(1) will print out a "\ No newline at end of file" indicator. While we do correctly handle this in the case where the new file has this indcator, we fail to parse patches where the old file is missing a newline at EOF. Fix this bug by handling and missing newline indicators in the old file. Add tests to verify that we can parse such files.
* | patch_parse: do not depend on parsed buffer's lifetimePatrick Steinhardt2019-07-051-0/+20
|/ | | | | | | | | | | When parsing a patch from a buffer, we let the patch lines point into the original buffer. While this is efficient use of resources, this also ties the lifetime of the parsed patch to the parsed buffer. As this behaviour is not documented anywhere in our API it is very surprising to its users. Untie the lifetime by duplicating the lines into the parsed patch. Add a test that verifies that lifetimes are indeed independent of each other.
* patch_parse.c: Handle CRLF in parse_header_startDrew DeVault2019-04-051-0/+9
|
* tests: diff: test parsing diffs with a new file with spaces in its pathErik Aigner2019-03-291-0/+9
| | | | | Add a test that verifies that we are able to parse patches which add a new file that has spaces in its path.
* patch: add support for partial patch applicationJason Haslam2018-11-051-0/+106
| | | | Add hunk callback parameter to git_apply__patch to allow hunks to be skipped.
* Convert usage of `git_buf_free` to new `git_buf_dispose`Patrick Steinhardt2018-06-101-1/+1
|
* patch_parse: allow parsing ambiguous patch headersPatrick Steinhardt2017-11-112-0/+16
| | | | | | | | | | | | | | | The git patch format allows for having unquoted paths with whitespaces inside. This format becomes ambiguous to parse, e.g. in the following example: diff --git a/file b/with spaces.txt b/file b/with spaces.txt While we cannot parse this in a correct way, we can instead use the "---" and "+++" lines to retrieve the file names, as the path is not followed by anything here but spans the complete remaining line. Because of this, we can simply bail outwhen parsing the "diff --git" header here without an actual error and then proceed to just take the paths from the other headers.
* diff: implement function to calculate patch IDPatrick Steinhardt2017-06-261-1/+60
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | The upstream git project provides the ability to calculate a so-called patch ID. Quoting from git-patch-id(1): A "patch ID" is nothing but a sum of SHA-1 of the file diffs associated with a patch, with whitespace and line numbers ignored." Patch IDs can be used to identify two patches which are probably the same thing, e.g. when a patch has been cherry-picked to another branch. This commit implements a new function `git_diff_patchid`, which gets a patch and derives an OID from the diff. Note the different terminology here: a patch in libgit2 are the differences in a single file and a diff can contain multiple patches for different files. The implementation matches the upstream implementation and should derive the same OID for the same diff. In fact, some code has been directly derived from the upstream implementation. The upstream implementation has two different modes to calculate patch IDs, which is the stable and unstable mode. The old way of calculating the patch IDs was unstable in a sense that a different ordering the diffs was leading to different results. This oversight was fixed in git 1.9, but as git tries hard to never break existing workflows, the old and unstable way is still default. The newer and stable way does not care for ordering of the diff hunks, and in fact it is the mode that should probably be used today. So right now, we only implement the stable way of generating the patch ID.
* diff: treat binary patches with no data specialethomson/diff-read-empty-binaryEdward Thomson2016-09-052-0/+11
| | | | | | When creating and printing diffs, deal with binary deltas that have binary data specially, versus diffs that have a binary file but lack the actual binary data.
* patch: differentiate not found and invalid patchesEdward Thomson2016-05-261-6/+75
|
* git_patch_parse_ctx: refcount the contextEdward Thomson2016-05-262-0/+2
|
* patch: `git_patch_from_patchfile` -> `git_patch_from_buffer`Edward Thomson2016-05-262-2/+4
|
* apply: test postimages that grow/shrink originalEdward Thomson2016-05-261-0/+89
| | | | | | | Test with some postimages that actually grow/shrink from the original, adding new lines or removing them. (Also do so without context to ensure that we can add/remove from a non-zero part of the line vector.)
* Introduce git_patch_options, handle prefixesEdward Thomson2016-05-262-4/+6
| | | | | Handle prefixes (in terms of number of path components) for patch parsing.
* patch_parse: test roundtrip patch parsing -> printEdward Thomson2016-05-261-0/+166
|
* patch_parse: ensure we can parse a patchEdward Thomson2016-05-261-0/+31
|
* apply: move patch data to patch_common.hEdward Thomson2016-05-261-0/+574