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

add .gitattributes #1756

Merged
merged 2 commits into from
May 17, 2019
Merged

add .gitattributes #1756

merged 2 commits into from
May 17, 2019

Conversation

jmjatlanta
Copy link
Contributor

This fixes #1754

By controlling how git handles text files on Windows, we can assure that the correct chain id gets generated.

Note: This change causes that all text files cloned by git are saved with LF, instead of the Windows standard CRLF. I believe there are no problems in permitting all files to retain their standard non-Windows encoding. But should this cause problems in some area, the .gitattributes file can be modified to control which line endings are applied to which files.

@pmconrad
Copy link
Contributor

Not sure if anyone is developing on mac or windows, nor what tools they are using, but I think most files should be in native encoding.
I know some editors on windows do not handle files with LF endings properly.
I also know that some sh implementations on windows choke on shell scripts with CRLF endings.

Opinions from mac/windows experts?

@abitmore
Copy link
Member

abitmore commented May 14, 2019

Replace * with genesis.json?

I guess this would work:

genesis.json -text

I don't think it's good to have text and eol at the same time, since they're conflicting. See https://git-scm.com/docs/gitattributes

text

Set
Setting the text attribute on a path enables end-of-line normalization and marks the path as a text file. End-of-line conversion takes place without guessing the content type.

Unset
Unsetting the text attribute on a path tells Git not to attempt any end-of-line conversion upon checkin or checkout.

eol
This attribute sets a specific line-ending style to be used in the working directory. It enables end-of-line conversion without any content checks, effectively setting the text attribute.

@jmjatlanta
Copy link
Contributor Author

jmjatlanta commented May 14, 2019

macOS uses LF, not CRLF.

I agree that we should only translate what is necessary. I was hoping to catch any commits with CRLF and convert them to LF, but that may be overly ambitious. And as you say, may cause grief in some editors.

It is my understanding that genesis.json text=unset will prevent the translation, even if somehow a CRLF gets into github for that file. Whereas genesis.json eol=lf will bring down genesis.json, translating CRLF to LF if necessary. I will test it out.

Update: I tested it, and it works. I even attempted an add, and when adding the file (which was already mentioned in the .gitattributes file), it displayed:

warning: CRLF will be replaced by LF in my_directory/myfile_crlf.txt.
The file will have its original line endings in your working directory

@abitmore
Copy link
Member

Windows, and DOS before it, uses a pair of CR and LF characters to terminate lines. UNIX (Including Linux and FreeBSD) uses an LF character only. OS X also uses a single LF character, but the classic Mac operating system used a single CR character for line breaks. https://www.editpadpro.com/tricklinebreak.html

@abitmore abitmore added this to the 3.2.0 - Feature Release milestone May 14, 2019
@pmconrad
Copy link
Contributor

I don't think it's good to have text and eol at the same time, since they're conflicting.

In my understanding there is no conflict (except that -text and eol on the same file is contradictory).

Normally, git tries to automatically detect if a file is a text file or a binary. If git thinks it's a text file it may apply certain conversions on checkout and commit whereas for binaries it doesn't. The text attribute merely overrides this automatic detection with an explicit setting.

Now, the eol attribute (and config settings like autocrlf) apply only to files that are to be treated as text files. They specify what kind of conversion is to be applied.

genesis.json should not be modified at all, so I agree that the appropriate setting for this would be -text.

Question is, should we set text=auto on certain file patterns? Like *.cpp, *.hpp, *.md etc.?

@abitmore
Copy link
Member

Question is, should we set text=auto on certain file patterns? Like *.cpp, *.hpp, *.md etc.?

Aren't they auto already?

@pmconrad
Copy link
Contributor

Aren't they auto already?

In my understanding this depends on the user's local git configuration core.autocrlf by default. With text=auto we would enforce it. I may be wrong though.

@jmjatlanta
Copy link
Contributor Author

It is my understanding that the following line does what we want:

genesis.json eol=lf

Interpretation: Handle all files in the typical way, with the exception of the genesis.json file. For that file, assure that the lf remains lf, and does not get converted to crlf for Windows users.

If the user has their [core] settings in any configuration, that is their preference, and should not affect BitShares. We are only requiring that genesis.json remain a certain way regardless of the platform.

Copy link
Contributor

@pmconrad pmconrad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I think consensus is to not add settings for any other files except genesis.json.

For genesis.json, both -text or eol=lf should produce identical results at this time, so I don't care which it is.

@jmjatlanta jmjatlanta merged commit 6a57bd9 into develop May 17, 2019
@abitmore abitmore deleted the jmj_1754 branch June 16, 2019 12:00
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

Successfully merging this pull request may close these issues.

3 participants