Ok, so I’ve been wrestling with Git and constant changes to resource.json files detected by Git, as I hear others have.
This is probably isn’t an issue at all in Linux or Mac environments, but those of us confined to Windows feel the pain.
So, the reason you keep seeing resource.json files that git wants you to commit is because they get updated by Ignition whenever it sees a change in a source file (python code.py files, etc). But, my file hasn’t changed since I pulled the code.py and resource.json, so why has that file changed?
Well, here’s the thing. When you update a script and save it in the designer the file gets saved with Linux style end of line (EOL) markers which are LF (line feed), but Windows files natively store with DOS style EOL markers CRLF (carriage return + line feed). Git tries to be smart about your environment and convert the files into your native file format when you pull the files, so it changes the LF end of line markers to CRLF.
Why do we care? Well, the gateway looks at each source file and generates a hash to see if the file has changed. The resource.json file you committed to the repository was created with hash generated from a file with LF EOL markers, but the one you just pulled down now has CRLF EOL markers, so it generates a different hash and updates the resource.json. Now Git sees that the file has changed to it flags it as needing to be committed.
So, the trick is to stop Git from changing the files as you commit or pull them.
Now, if you work in an environment with Windows an Linux machines you will have other issues, but in a Windows-only environment this seems to be working for me.
I use the command line Git tools, so you may need to find where to change it in your tool, but basically tell it to use LF for line ends.
In the project directory create (or modify) the file .gitattributes. This may be more than necessary, but mine looks like this:
# Set the default behavior, in case people don't have core.autocrlf set.
text=lf
# Force LF line endings on checkout for project script files. If this is not set, nuisance changes (line ending only) will be detected, causing resource.json files to update.
ignition/script-python/** text eol=lf
# Force LF line endings on checkout for all resource.json files.
resource.json text eol=lf
*.json text eol=lf
*.py text eol=lf
Hope this helps someone.
Enjoy!
Craig L.