Repository navigation
Conversation
0b6ccf6 to
bc8f923
Compare
Mark wrongenc.inc files as binary in .gitattributes to prevent encoding conversion issues on different platforms. These files contain intentional Latin-1 encoded content for testing Sphinx's encoding handling and should remain byte-for-byte identical. Fixes git errors like: - "failed to encode from UTF-8 to latin-1" - "patch does not apply" in pre-commit hooks - stash/unstash failures with these files 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
AA-Turner
left a comment
There was a problem hiding this comment.
I don't think this is right; the files are text, not binary content. My attempt here was to properly mark the encoding as I understand that Git's internal index is stored in Unicode, whereas we have a few test files that we intentionally have in different encodings.
Does macOS support the Latin-1 codec in general? I imagine there's no support for Windows-1252? (the default Windows codepage)
A third option would be to remove these files from the repo and have the tests write them to disk each time, which might be somewhat clearer in the intent.
A
|
I am on macOS and I would like to help because I have encountered the issue too. The problem is that I do not know how to reproduce it. I did not encounter it while working on some PRs I merged last few days, but I definitely had the issue about five days ago, and it was a bit painful because one had to be careful to not do |
Emacs on macOS definitely support the Latin-1 codec and probably Windows-1252 inclusive of the problem of EOLs. There are some issues with Unicode rather when one copies files to external hard disks where the macOS might automatically change the type of Unicode normalization, but this looks like something else. |
I thought yes
This seems easiest Although I also cannot replicate it now :( which is extremely confusing. Maybe this was a temporary bug somewhere else (git, iterm, mac?)? So maybe this is just resolved, and we can close this, and if it comes up again hopefully someone will find this and not feel despair. |
|
I am not 100% sure but it does look as if it is 5cf62e5 which fixed the issue for me once I had updated my locale. But trying to revert it I fail so far to trigger Git into complaining again about those wrongly encoded files. |
Confusingly I only made a fork a few days ago, so I would for sure have had this already when I started seeing the issue. |
|
I got the same error (Win11/WSL2). Once I touched those files they were "stuck" and could not be reverted/discarded anymore. |
|
I suspect the issue lies with syntax in gitattributes - the value should be On both a modern Ubuntu Linux and macOS, the results are the same: $ file --mime tests/roots/test-root/wrongenc.inc tests/roots/test-warnings/wrongenc.inc
tests/roots/test-root/wrongenc.inc: text/plain; charset=iso-8859-1
tests/roots/test-warnings/wrongenc.inc: text/plain; charset=iso-8859-1Setting diff --git a/.gitattributes b/.gitattributes
index c8acd1081..d44a1f750 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -51,8 +51,8 @@ tests/roots/test-pycode/cp_1251_coded.py dos
# Non UTF-8 encodings
tests/roots/test-pycode/cp_1251_coded.py working-tree-encoding=windows-1251
-tests/roots/test-root/wrongenc.inc working-tree-encoding=latin-1
-tests/roots/test-warnings/wrongenc.inc working-tree-encoding=latin-1
+tests/roots/test-root/wrongenc.inc working-tree-encoding=iso-8859
+tests/roots/test-warnings/wrongenc.inc working-tree-encoding=iso-8859
# Generated files
# https://github.com/github/linguist/blob/master/docs/overrides.md$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: .gitattributes
no changes added to commit (use "git add" and/or "git commit -a")P.S. I'm not sure why setting |
Try to avoid files marked as changed due to an error when auto-recoding from UTF-8 to ISO-8859-1 see sphinx-doc#13811 (comment)
|
Same problem here, on a Debian/stable system. I don't remember whether it started right from the beginning (setup of a local mirror of my fork) or after the first changes or a rebase. The workaround proposed by miketheman in #13811 (comment) helped, although now an inofficial alias is replaced by an incomplete name¹. ¹ The standard ISO-8859 defines a series of several encodings but for some mysterious reason the correct name "ISO-8859-1" does not help :(. |
I took a look into gitattribute's documentation and came to think that the solution originally proposed on this PR is actually better than the alternatives. My argument is as follows: by construction the text file is assigned a wrong encoding, since git stores all of it's texts on UTF-8, in some platforms it will fail when trying to convert it internally to UFT-8 and keep it as is (according to git docs If a Git client, that does not support the working-tree-encoding attribute, adds a new file ... will be stored "as-is" internally). In addition to that, Reencoding content to non-UTF encodings can cause errors as the conversion might not be UTF-8 round trip safe. Note that since it is trying to convert the file to UTF-8, in some platforms it will succeed and in other, maybe not (as is the case with some developers interested in contributing to this repository, just like me). Continuing the argument, if one marks the text files with wrong encodings as binary the file will have the same hash for everybody, regardless of the developer platform. On the other hand, even if the encoding is changed to one that apparently is consistent in all platforms, nothing can guarantee that a future change in the operating system, or even on git, cannot break this test again. So, I my opinion marking this file as binary, as originally proposed is simple and solves the issue. |
|
Applied @miketheman's suggestion in 4f23c99 A |
Purpose
There was an existing
.gitattributesfor these files, but it wasn't working on my system (M2 mac). I was unable to restore or stash these files. Which made rebasing difficulty. This approach fixed the git issues for me.I was getting errors like:
whenever I tried to restore, stash, or rebase.
Full disclosure - this was a level of git that was beyond me so this is an AI assisted PR. Claude summarizes the downsides as:
Although I was able to open them in neovim without issue.
References
It looks like there was a recent similar change: 5cf62e5