summaryrefslogtreecommitdiff
path: root/tests/apply
Commit message (Collapse)AuthorAgeFilesLines
* tests: apply: verify that we correctly truncate the source bufferPatrick Steinhardt2019-02-211-0/+33
| | | | | | | | | | Previously, we would fail to correctly truncate the source buffer if the source has more than one line and ends with a non-newline character. In the following call, we thus truncate the source string in the middle of the second line. Without the bug fixed, we would successfully apply the patch to the source and return success. With the overflow being fixed, we should return an error now.
* index: use new enum and structure namesEdward Thomson2018-12-011-2/+2
| | | | Use the new-style index names throughout our own codebase.
* tests: move apply_helpers functions into own compilation unitPatrick Steinhardt2018-11-282-126/+141
| | | | | | | | | | | Currently, the "apply_helper" functions used for testing the apply logic are all statically defined in the "apply_helpers.h" header file. This may lead to warnings from the compiler in case where this header file is included, but not all functions it brings along are used in the compilation unit where it has been included into. Fix these potential warnings by moving the implementation into its own compilation unit "apply_helpers.c".
* Merge pull request #4847 from noahp/noahp/null-arg-fixesEdward Thomson2018-11-181-1/+2
|\ | | | | tests: 🌀 address two null argument instances
| * tests: address two null argument instancesNoah Pendleton2018-11-131-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Handle two null argument cases that occur in the unit tests. One is in library code, the other is in test code. Detected by running unit tests with undefined behavior sanitizer: ```bash # build mkdir build && cd build cmake -DBUILD_CLAR=ON -DCMAKE_C_FLAGS="-fsanitize=address \ -fsanitize=undefined -fstack-usage -static-libasan" .. cmake --build . # run with asan ASAN_OPTIONS="allocator_may_return_null=1" ./libgit2_clar ... ............../libgit2/src/apply.c:316:3: runtime error: null pointer \ passed as argument 1, which is declared to never be null ...................../libgit2/tests/apply/fromfile.c:46:3: runtime \ error: null pointer passed as argument 1, which is declared to never be null ```
* | tests: apply: fix reference to deprecated `git_buf_free`Patrick Steinhardt2018-11-131-2/+2
| | | | | | | | | | | | | | | | | | Since commit 56ffdfc61 (buffer: deprecate `git_buf_free` in favor of `git_buf_dispose`, 2018-02-08), the function `git_buf_free` is deprecated and shall not be used anymore. As part of the new apply framework that has been cooking for quite some time some new references have been introduced to that deprecated function. Replace them with calls to `git_buf_dispose`.
* | tests: apply: fix missing `cl_git_pass` wrappersPatrick Steinhardt2018-11-132-4/+4
| | | | | | | | | | | | Some function calls in the new "apply" test suite were missing the checks whether they succeeded as expected. Fix this by adding the missing `cl_git_pass` wrappers.
* | test: ensure applying a patch can't delete a file twiceethomson/applyEdward Thomson2018-11-052-0/+45
| |
* | apply: test re-adding a file after removing itEdward Thomson2018-11-052-0/+50
| | | | | | | | | | | | Ensure that we can add a file back after it's been removed. Update the renamed/deleted validation in application to not apply to deltas that are adding files to support this.
* | apply: test modifying a file after renaming itEdward Thomson2018-11-052-0/+72
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Ensure that we cannot modify a file after it's been renamed out of the way. If multiple deltas exist for a single path, ensure that we do not attempt to modify a file after it's been renamed out of the way. To support this, we must track the paths that have been removed or renamed; add to a string map when we remove a path and remove from the string map if we recreate a path. Validate that we are not applying to a path that is in this map, unless the delta is a rename, since git supports renaming one file to two different places in two different deltas. Further, test that we cannot apply a modification delta to a path that will be created in the future by a rename (a path that does not yet exist.)
* | apply: test renaming a file after modifying itEdward Thomson2018-11-052-5/+20
| | | | | | | | | | | | | | | | | | | | Multiple deltas can exist in a diff, and can be applied in-order. If there exists a delta that modifies a file followed by a delta that renames that file, then both will be captured. The modification delta will be applied and the resulting file will be staged with the original filename. The rename delta will be independently applied - to the original file (not the modified file from the original delta) and staged independently.
* | apply: test that we can't rename a file after modifying itEdward Thomson2018-11-052-0/+36
| | | | | | | | | | | | | | | | | | Multiple deltas can exist in a diff, and can be applied in-order. However if there exists a delta that renames a file, it must be first, so that other deltas can reference the resulting target file. git enforces this (`error: already exists in index`), so ensure that we do, too.
* | apply: test modify delta after rename deltaEdward Thomson2018-11-052-0/+50
| | | | | | | | Ensure that we can apply a delta after renaming a file.
* | apply: test multiple deltas to new fileEdward Thomson2018-11-052-0/+43
| |
* | apply: handle multiple deltas to the same fileEdward Thomson2018-11-052-0/+47
| | | | | | | | | | | | | | | | | | | | | | | | | | git allows a patch file to contain multiple deltas to the same file: although it does not produce files in this format itself, this could be the result of concatenating two different patch files that affected the same file. git apply behaves by applying this next delta to the existing postimage of the file. We should do the same. If we have previously seen a file, and produced a postimage for it, we will load that postimage and apply the current delta to that. If we have not, get the file from the preimage.
* | apply: test rename 1 to 2Edward Thomson2018-11-052-0/+36
| | | | | | | | | | | | | | Test that a patch can contain two deltas that appear to rename an initial source file to two different destination paths. Git creates both target files with the initial source contents; ensure that we do, too.
* | apply: test rename 2 to 1Edward Thomson2018-11-052-0/+34
| | | | | | | | | | | | | | Test that we can apply a patch that renames two different files to the same target filename. Git itself handles this scenario in a last-write wins, such that the rename listed last is the one persisted in the target. Ensure that we do the same.
* | apply: test circular renameEdward Thomson2018-11-052-0/+35
| | | | | | | | Test a rename from A->B simultaneous with a rename from B->A.
* | apply: test rename A -> B -> C scenariosEdward Thomson2018-11-052-0/+142
| | | | | | | | | | | | | | Test that we can rename some file from B->C and then rename some other file from A->B. Do this with both exact rename patches (eg `rename from ...` / `rename to ...`) and patches that remove the files and replace them entirely.
* | apply: handle exact renamesEdward Thomson2018-11-052-0/+31
| | | | | | | | | | | | | | Deltas containing exact renames are special; they simple indicate that a file was renamed without providing additional metadata (like the filemode). Teach the reader to provide the file mode and use the preimage's filemode in the case that the delta does not provide one.)
* | apply: validate unchanged mode when applying bothEdward Thomson2018-11-051-0/+17
| | | | | | | | | | | | | | When applying to both the index and the working directory, ensure that the working directory's mode matches the index's mode. It's not sufficient to look only at the hashed object id to determine that the file is unchanged, git also takes the mode into account.
* | apply: test a patch with rename and modificationEdward Thomson2018-11-052-0/+40
| | | | | | | | | | Create a test applying a patch with a rename and a modification of a file.
* | patch: add tests for aborting hunk callbackJason Haslam2018-11-051-0/+71
| |
* | patch: add support for partial patch applicationJason Haslam2018-11-052-0/+207
| | | | | | | | Add hunk callback parameter to git_apply__patch to allow hunks to be skipped.
* | apply: introduce a hunk callbackEdward Thomson2018-11-053-2/+40
| | | | | | | | | | Introduce a callback to patch application that allows consumers to cancel hunk application.
* | apply tests: tests a diff w/ many small changesEdward Thomson2018-11-052-0/+112
| |
* | apply tests: test delta callback skipEdward Thomson2018-11-051-0/+38
| | | | | | | | | | Test that we can return a non-zero value from the apply delta callback and it will skip the application of a given delta.
* | apply tests: test delta callback errorsEdward Thomson2018-11-051-0/+52
| | | | | | | | | | Test that we can return an error from the apply delta callback and the error code is propagated back to the caller.
* | apply: move location to an argument, not the optsEdward Thomson2018-11-054-87/+29
| | | | | | | | | | | | | | | | Move the location option to an argument, out of the options structure. This allows the options structure to be re-used for functions that don't need to know the location, since it's implicit in their functionality. For example, `git_apply_tree` should not take a location, but is expected to take all the other options.
* | apply tests: ensure mode changes occurEdward Thomson2018-11-053-0/+62
| | | | | | | | Test that a mode change is reflected in the working directory or index.
* | apply tests: test with CR/LF filteringEdward Thomson2018-11-051-0/+53
| | | | | | | | | | | | Ensure that we accurately CR/LF filter when reading from the working directory. If we did not, we would erroneously fail to apply the patch because the index contents did not match the working directory contents.
* | apply: validate workdir contents match index for BOTHEdward Thomson2018-11-051-0/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | When applying to both the index and the working directory, ensure that the index contents match the working directory. This mirrors the requirement in `git apply --index`. This also means that - along with the prior commit that uses the working directory contents as the checkout baseline - we no longer expect conflicts during checkout. So remove the special-case error handling for checkout conflicts. (Any checkout conflict now would be because the file was actually modified between the start of patch application and the checkout.)
* | apply tests: ensure we can patch a modified fileEdward Thomson2018-11-053-0/+125
| | | | | | | | | | | | | | | | Patch application need not be on an unmodified file; applying to an already changed file is supported provided the patch still applies cleanly. Add tests that modifies the contents of a file then applies the patch and ensures that the patch applies cleanly, and the original changes are also kept.
* | apply tests: test index+workdir applicationEdward Thomson2018-11-051-0/+281
| | | | | | | | | | | | Test application with `GIT_APPLY_LOCATION_BOTH`, which emulates `git apply --index`, updating both the index and the working directory with the postimage.
* | apply test: apply with non-conflicting changesEdward Thomson2018-11-052-0/+70
| | | | | | | | | | | | Ensure that we can apply to the working directory or the index when the application target is modified, so long as there are not conflicting changes to the items.
* | apply tests: ensure apply failures leave index unmodifiedEdward Thomson2018-11-051-0/+34
| |
* | apply tests: modified wd items are ok when applying to indexEdward Thomson2018-11-041-0/+43
| | | | | | | | | | | | When applying to the index (using `GIT_APPLY_LOCATION_INDEX`), ensure that items modified in the working directory do not conflict with the application.
* | apply tests: ensure we can add and remove files from the indexEdward Thomson2018-11-041-0/+56
| | | | | | | | | | Add a test that adds a new file, and another that removes a file when applying using `GIT_APPLY_LOCATION_INDEX` to ensure that they work.
* | apply tests: GIT_APPLY_LOCATION_INDEX with parsed patchesEdward Thomson2018-11-041-0/+28
| |
* | apply tests: GIT_APPLY_LOCATION_INDEX with generated patchesEdward Thomson2018-11-042-0/+94
| | | | | | | | | | Test a simple patch application with `GIT_APPLY_LOCATION_INDEX`, which emulates `git apply --cached`.
* | apply tests: move helpers into common areaEdward Thomson2018-11-042-152/+155
| |
* | apply: test that failures don't dirty workdirEdward Thomson2018-11-041-0/+29
| | | | | | | | | | | | | | | | | | | | Ensure that when a patch application fails (due to a conflict in the working directory, for example) that we do not half-apply the patch or otherwise leave the working directory dirty. This is rather obvious in our current apply implementation (we do a two step process: one to create the post-image and one to check it out) but this test is a safety net for future refactoring or improvements.
* | apply: test a patch can be applied even with a modified indexEdward Thomson2018-11-041-22/+15
| | | | | | | | | | | | | | Ensure that we can apply a patch to the working directory, even to files that are modified in the index (as long as the working directory contents match the preimage - such that the working directory is unmodified from HEAD).
* | apply: test that the index is not modifiedEdward Thomson2018-11-041-0/+76
| | | | | | | | | | Ensure that by default, when using GIT_APPLY_LOCATION_WORKDIR, that patch application does not update the index, only the working directory.
* | apply tests: separate common patch hunksEdward Thomson2018-11-041-73/+59
| | | | | | | | | | | | | | Move the commonly-used patch hunks into a single constant location. This allows us to avoid re-declaring them in each test, and allows us to compose them to build a larger patch file that includes all the hunks.
* | apply tests: use `git_iterator_foreach` for testsEdward Thomson2018-11-041-51/+69
| | | | | | | | | | | | | | | | Use the new `git_iterator_foreach` API to validate the workdir against the expected workdir values instead of using the paired/multi iterator comparison callback. This allows us to use the `git_iterator_foreach` to validate the index as well, instead of assuming that the index and HEAD must always match.
* | apply: handle file additionsEdward Thomson2018-11-041-4/+49
| | | | | | | | | | | | Don't attempt to read the postimage file during a file addition, simply use an empty buffer as the postimage. Also, test that we can handle file additions.
* | apply: handle file deletionsEdward Thomson2018-11-041-0/+49
| | | | | | | | | | | | If the file was deleted in the postimage, do not attempt to update the target. Instead, ignore it and simply allow it to stay removed in our computed postimage. Also, test that we can handle file deletions.
* | apply: test `git_apply` with a parsed patchEdward Thomson2018-11-041-0/+49
| | | | | | | | | | Ensure that we can apply a simple patch to the working directory when we have parsed it from a patch file.
* | apply: test `git_apply` application to a workdirEdward Thomson2018-11-041-0/+124
| | | | | | | | | | Introduce a standard test applying a diff to a working directory with no complications.