Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Files with .gitattributes Rules Do Not Reprocess on Branch Switch #145

Open
IgorTodorovskiIBM opened this issue Jan 17, 2025 · 0 comments
Open

Comments

@IgorTodorovskiIBM
Copy link
Collaborator

IgorTodorovskiIBM commented Jan 17, 2025

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 .  
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant