zopencommunity / zopencommunity/gitport
Files with .gitattributes Rules Do Not Reprocess on Branch Switch
Nobody has claimed this yet.
- Dominant language
- Shell
- Stars
- 10
- Forks
- 7
- PR merge metrics
- No merged PRs in 30d
Description
This issue was identified by @MikeFultonDev.
When switching between branches in a repository that uses .gitattributes to define the encoding rules (e.g., zos-working-tree-encoding=IBM-1047), existing files in the working tree are not reprocessed to apply the new branch's .gitattributes rules. This behavior only applies to files that are already present in the working directory; new or exclusive files from the branch are correctly processed and encoded.
This results in an inconsistent state where some files have the correct encoding, while others retain the encoding from the previous branch.
Steps to Reproduce
git clone https://github.com/IgorTodorovskiIBM/GitAttributeTest && cd GitAttributeTest
ls -lT
# result:
t ISO8859-1 T=on -rw-rw-r-- 1 ITODORO CDEV 7 Jan 17 11:21 a.mac
t ISO8859-1 T=on -rw-rw-r-- 1 ITODORO CDEV 7 Jan 17 11:21 b.mac
t ISO8859-1 T=on -rw-rw-r-- 1 ITODORO CDEV 7 Jan 17 11:21 c.mac
main branch has files already encoded in ISO-8859-1.
Switch to another branch (attribute) where the .gitattributes specifies encoding zos-working-tree-encoding=IBM-1047.
git checkout attribute
cat .gitattributes
ls -lT
# results:
git checkout attribute
branch 'attribute' set up to track 'origin/attribute'.
Switched to a new branch 'attribute'
[ITODORO@ZOSCAN2B ~/projects/GitAttributeTest]$ cat .gitattributes
*.mac text zos-working-tree-encoding=IBM-1047
[ITODORO@ZOSCAN2B ~/projects/GitAttributeTest]$ ls -lT
total 8
t ISO8859-1 T=on -rw-rw-r-- 1 ITODORO CDEV 7 Jan 17 11:21 a.mac
t ISO8859-1 T=on -rw-rw-r-- 1 ITODORO CDEV 7 Jan 17 11:21 b.mac
t ISO8859-1 T=on -rw-rw-r-- 1 ITODORO CDEV 7 Jan 17 11:21 c.mac
t IBM-1047 T=on -rw-rw-r-- 1 ITODORO CDEV 9 Jan 17 11:21 e.mac
Only new or exclusive files in the attribute branch are encoded in IBM-1047. Pre-existing files are not reprocessed.
Workarounds
The following workarounds have been identified but are not ideal for frequent branch switching:
Removing all tracked files and re-checking out:
git ls-files -z | xargs -0 rm -f
git checkout .
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the behavior with the GitAttributeTest repository and the branch switch from main to attribute, then inspect how git checkout applies the .gitattributes rule for existing files. Use the .gitattributes entry for zos-working-tree-encoding=IBM-1047 as the starting point. Done means existing tracked files are reprocessed when the branch changes the applicable encoding rule.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100