Update CRLF filtering to match modern git#4904
Conversation
Move the crlf_data folders reponsible for holding the state of the filters going into the working directory to "to_workdir" variations of the folder name to accommodate future growth into the "to odb" filter variation. Update the script to create these new folders as appopriate.
|
There were some questions in #3285 about the value of checking in all this test data. Yes, it is obnoxious but very useful. It's hard to generate this on-the-fly since:
We could do something like check in a zip that we extract, which would have the benefit of only having a single file checked in to the repository, but that feels like the only benefit and otherwise feels icky to me. |
dde3f49 to
e781ed2
Compare
After sandboxing the crlf directory, remove the working directory contents. This allows us to package data within the crlf directory (for simplicity, this allows us to script the to-odb and to-workdir crlf filter conversion data in a single location).
Include a shell script that will generate the expected data of OIDs and failures for calling git.git to capture its output as a test resource. Right now, there is no need to differentiate different systems as git behaves the same on all systems IIRC. Signed-off-by: Sven Strickroth <email@cs-ware.de>
Re-use the existing crlf data generation script for creating the to-odb dataset. Also, store the actual file contents instead of the ID so that we can identify differences instead of detecting that differences exist.
Use the crlf data scripts to produce a corpus of known-good data in "git" format (aka ODB format) from a variety of files with different line endings. `git` created these files running `git add` to stage the contents then extracting the data from the repository. We'll use these to ensure that we create identical contents when we add files into the index.
Given a variety of combinations of core.autocrlf, core.safecrlf settings and attributes settings, test that we add files to index the same way (regarding OIDs and fatal errors) as a known-good test resource created by git.git. Signed-off-by: Sven Strickroth <email@cs-ware.de>
Don't simply fail when the expected output does not match the data in the index; instead, provide a detailed output about the system, file, and settings that caused the failure so that developers can better isolate the problem(s).
Examine the recent CRLF changes to git by Torsten Bögershausen and include similar changes to update our CRLF logic to match. Note: Torsten Bögershausen has previously agreed to allow his changes to be included in libgit2.
This is a cherry-pick of the tests from the following commits: core.autocrlf=true and core.safecrlf=true did not fail on LF-only file as vanilla git does Adding a CRLF-file with core.autocrlf=input and core.safecrlf=true does not fail as with vanilla git Make files with #CR!=#CRLF not fail with core.safecrlf=true Reported-by: Yue Lin Ho <b8732003@student.nsysu.edu.tw> Signed-off-by: Sven Strickroth <email@cs-ware.de>
e781ed2 to
2a9b010
Compare
| * check out over it. | ||
| */ | ||
| git_buf_puts(&reponame, "crlf"); | ||
| cl_git_pass(git_path_direach(&reponame, 0, unlink_file, NULL)); |
There was a problem hiding this comment.
Can't we use your nifty new workdir iterator for that?
| cl_assert_equal_i(GITERR_FILTER, giterr_last()->klass); | ||
| cl_assert_equal_s(expected_contents.ptr, giterr_last()->message); | ||
| } else { | ||
| cl_fail("unexpected index failure"); |
There was a problem hiding this comment.
Ugh. Okay, so you do already fix up a lot of these. Maybe want to squash those two commits together?
There was a problem hiding this comment.
Yeah, I did that so that @csware's commits kept him as the author to make sure that he got credit in the log.
| filename); | ||
| else | ||
| giterr_set( | ||
| GITERR_FILTER, "CRLF would be replaced by LF"); |
There was a problem hiding this comment.
Oh, how I wish that git'd just track the files you add, without ever caring about their contents at all and leaving that problem to the user instead.
There was a problem hiding this comment.
With SafeCRLF enabled Git must care for the content.
|
Thanks, @pks-t, I'm going through and resolving your comments as I fix them locally. I'm stepping away now but I'll push up fixes shortly. |
Wrap function calls in the `checkout::crlf` tests with `cl_git_pass`, `cl_assert`, etc. to ensure that they're successful.
|
OK, I added some missing |
#3285 indicated that we had issues with compatibility when CRLF-filtering files when adding them to the index. This takes that pull request with a few modifications:
crlf_datafolders fromposixandwindowsto have a suffix indicating that they're the "to workdir" direction. This will let us add the "to odb" folders in the same location.autocrlf/safecrlf/ attributes settings is failing.Big thanks to @csware for all the work on this. Having the test corpus from git is a huge help to ensure that we are getting this right.