Skip to content

Add appendable global .gitattributes file#19

Draft
SaschaMann wants to merge 5 commits into
mainfrom
gitattr
Draft

Add appendable global .gitattributes file#19
SaschaMann wants to merge 5 commits into
mainfrom
gitattr

Conversation

@SaschaMann

Copy link
Copy Markdown
Contributor

This should prevent most line-ending issues, e.g. exercism/docs#148.

@SleeplessByte

@SaschaMann
SaschaMann marked this pull request as draft June 18, 2021 16:54
@SaschaMann

Copy link
Copy Markdown
Contributor Author

This seems fairly harmless as it can't delete any labels.

@SaschaMann

This comment has been minimized.

@SaschaMann

Copy link
Copy Markdown
Contributor Author

This should prevent most line-ending issues, e.g.
exercism/docs#148.
*.* text eol=lf

# Windows forced line-endings
/.idea/* text eol=crlf

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is there a reason why we need to mention IDE specific files at all? I understand the *.sln and similar MS IDE files which today are also used by their dotnet CLI, but IntelliJ config files shouldn't be necessary anywhere.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Because contributors and maintainers will use these tools and if we don't include them, their tools will break.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would this make the files in the .idea directory on Linux/macOS also have CRLF line endings?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In my opinion IDE specific files should be ignored globally and shouoldn't be in any repository at all.

Unless you enforce a specific IDE at least project wide. As far as I know, such an enforcement only exists for the Delphi, Pharo and Elisp tracks. And here the enforcement is more or less given by the nature of the languages, that no standalone compilers exist.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In my opinion IDE specific files should be ignored globally and shouoldn't be in any repository at all.

And I don't agree. Unfortunately you need to know that you need to configure something in order for a repository to not break. And many people don't actually know how to configure something.

On top of that, it's almost impossible to override .gitattributes for "some globs", so in this case leaving editor configurations out will actively break people's environments.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How should a git repository break things that are not intended to be part of the repository?

It is some IDE specific stuff, that should never be committed. So git will never temper with its line endings.

So how will removing this break peoples stuff?

@SleeplessByte SleeplessByte Jun 22, 2021

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Because .idea isn't ignored as a folder, nor is .sln. So their repo will break, and can only unbreak if they now manually add it to the ignore (and fix line-endings, and git remove it).

Which we can't do exercism-wide, because repos that require IntelliJ or Visual Studio (not code) would require some of the files in those directories to be commited.

I absolutely agree with you that in an ideal world it would be not in here at all.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Again, I expect IDE files to be ignored on the users host, or not to be commited at all. I accept that there are *.sln files, for the dotnet tracks, its just how their tooling works, though there is not a single track that requires .idea beeing in the repository. So why should it ever be commited?

For erlang I would not accept a PR containing them. And if accidental commit breaks the committers IDE, I do not care. It was their fault to commit files that weren't intended for comitting.

A .idea/ in a global git-ignore file, will ignore the folder and anything within it. Adding this to a global ignore file would be the solution for the problem.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

And if there will ever be a track requiring .idea in their repository, they still can add the necessary attributes to their repo-append.

Comment on lines +20 to +29
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Will we really ever have those binary document files within a git repository?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

docs and some of the website repos do, tracks might. I don't see why we would leave it out if we know how to not break those files if they're ever present.

It doesn't cost us anything to have these on there, right?

Comment on lines +36 to +57
*.png binary
*.jpg binary
*.jpeg binary
*.gif binary
*.ico binary
*.mov binary
*.mp4 binary
*.mp3 binary
*.flv binary
*.fla binary
*.swf binary
*.gz binary
*.zip binary
*.7z binary
*.ttf binary
*.eot binary
*.woff binary
*.pyc binary
*.pdf binary
*.ez binary
*.bz2 binary
*.swp binary

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This selection of binary formats again seems very broad to me, why should there ever be such files within a repository?

I can accept images, but vidoe?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have a few practice exercises in mind about simulating something. Those may benefit from having a video visualisation of the expected result, so I don't think it's impossible that there'll ever be video files somewhere on Exercism (though they'd probably be added via git lfs or in a separate repo)

@iHiD

This comment has been minimized.

*.* text eol=lf

# Windows forced line-endings
/.idea/* text eol=crlf

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would this make the files in the .idea directory on Linux/macOS also have CRLF line endings?

Comment on lines +11 to +17
# Custom for Visual Studio
*.cs diff=csharp
*.sln merge=union
*.csproj merge=union
*.vbproj merge=union
*.fsproj merge=union
*.dbproj merge=union

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm wondering if this should be in the global .gitattributes or just in an appends file in the C#/F#/VB repos.

@ErikSchierboom

Copy link
Copy Markdown
Member

@SaschaMann linked to https://rehansaeed.com/gitattributes-best-practices/ which contains the following:

# Force bash scripts to always use lf line endings so that if a repo is accessed
# in Unix via a file share from Windows, the scripts will work.
*.sh text eol=lf

This is taken from the dotnet/corefx .gitattributes file and I quite like it. Maybe we can add that?

@iHiD

iHiD commented Jun 22, 2021

Copy link
Copy Markdown
Member

My take on this, is that there's no downside to being over-zealous in this file. While I get it's in some ways annoying to have files listed that shouldn't be in git (and that most-likely won't get to our git repos), I don't see a downside to being overtly cautious. So while adding project files, or IDE files to this may feel unnecessary, if someone starts a track for "CsharpScript" and that reuses `. csproj, I'd rather not have to remember to add this as an append, and if someone does upload an PDF because they feel its important (e.g. a licence), I'd rather that other maintainer who tries to use that repo later doesn't have to fight with line-endings as part of that. Even if we would rather they found a way to not upload the PDF. ie, I'd rather be proactive in this, rather than reactively trying to police all commits to ensure that such files don't get added.

So laying any general thoughts on what should/shouldn't be here in an ideal world, are there any downsides from a functional perspective to adding this file everywhere?

@iHiD

iHiD commented Jun 22, 2021

Copy link
Copy Markdown
Member

@SaschaMann linked to https://rehansaeed.com/gitattributes-best-practices/ which contains the following:

# Force bash scripts to always use lf line endings so that if a repo is accessed
# in Unix via a file share from Windows, the scripts will work.
*.sh text eol=lf

This is taken from the dotnet/corefx .gitattributes file and I quite like it. Maybe we can add that?

@ErikSchierboom Want to add this as a GitHub "suggestion" in some appropriate spot?

@SaschaMann

Copy link
Copy Markdown
Contributor Author

@ErikSchierboom Do you want to add the batch-equivalent listed in that post too?

# Force batch scripts to always use CRLF line endings so that if a repo is accessed
# in Windows via a file share from Linux, the scripts will work.
*.{cmd,[cC][mM][dD]} text eol=crlf
*.{bat,[bB][aA][tT]} text eol=crlf

Comment thread global-files/.gitattributes
@ErikSchierboom

Copy link
Copy Markdown
Member

@ErikSchierboom Want to add this as a GitHub "suggestion" in some appropriate spot?

Done.

@ErikSchierboom Do you want to add the batch-equivalent listed in that post too?

🤷 I find that scenario for more unlikely than the shell based one, so I would be fine with adding it or not having it.

@SaschaMann

Copy link
Copy Markdown
Contributor Author

🤷 I find that scenario for more unlikely than the shell based one, so I would be fine with adding it or not having it.

I don't care much either, but there seem to be a fair amount of .bat scripts: https://github.com/search?q=org%3Aexercism++extension%3Abat&type=Code&ref=advsearch&l=&l=

Co-authored-by: Erik Schierboom <erik_schierboom@hotmail.com>
@ErikSchierboom

Copy link
Copy Markdown
Member

I don't care much either, but there seem to be a fair amount of .bat scripts:

Maybe just add it then?

Comment thread global-files/.gitattributes
Comment thread global-files/.gitattributes
@SaschaMann

SaschaMann commented Jun 22, 2021

Copy link
Copy Markdown
Contributor Author

GitHub's UI is being annoying, need to check manually that the newlines at the end are correct once it's ready to be merged (@ErikSchierboom it's the same issue as we had before)

@ErikSchierboom

Copy link
Copy Markdown
Member

I'm off today, but I'll check tomorrow @SaschaMann!

@ErikSchierboom

Copy link
Copy Markdown
Member

@SaschaMann It looked like the newline was indeed missing, so I've added it in 0182cd6. I've checked with both vi and a bit of F# code, and both seem to confirm that there is now an empty line at the end of the file.

@ErikSchierboom

Copy link
Copy Markdown
Member

I want to resurrect this issue, as I've been bitten by this again last week.
I'm fine with having the .gitattributes be fairly exhaustive, even if that means having things in there that might only apply to a couple of tracks. The appends system works well, but can be hard for people to understand, so this way we don't need that. I also think that most people will just ignore this file, so their contents matter less.

The following tracks already have a .gitattributes file:

./prolog/.gitattributes
./cfml/.gitattributes
./fsharp-test-runner/.gitattributes
./gleam/.gitattributes
./csharp-test-runner/.gitattributes
./typescript/.gitattributes
./solutions/.gitattributes
./request-new-language-track/.gitattributes
./java/.gitattributes
./elm/.gitattributes
./vbnet/.gitattributes
./docs/.gitattributes
./bash/.gitattributes
./pharo-smalltalk/.gitattributes
./csharp/.gitattributes
./julia/.gitattributes
./javascript/.gitattributes
./x86-64-assembly/.gitattributes

Before we can merge this, we should consider what to do with these tracks. Do we want to do a diff and have the missing lines in an appends file? Do we just want to move it to an appends file (leading to duplicate entries)?

@SleeplessByte

SleeplessByte commented Oct 22, 2021

Copy link
Copy Markdown
Member

How does this solve the hard to understand appends system?

There should not be duplicate entries. Some tooling will complain when you do and it's hard to debug.

@ErikSchierboom

Copy link
Copy Markdown
Member

How does this solve the hard to understand appends system?

Well, hopefully it is full-fledged enough for most tracks not having to bother with an appends file.

There should not be duplicate entries. Some tooling will complain when you do and it's hard to debug.

Right. We should then do something a bit more involved for those tracks then.

@SleeplessByte

SleeplessByte commented Oct 22, 2021

Copy link
Copy Markdown
Member

It's a small enough list to go through a diff mnanually and append it to the bottom. The challenge is .gitattributes is evaluated from top to bottom, I think, so overrides below others work differently than above them.

@SaschaMann

SaschaMann commented Mar 4, 2022

Copy link
Copy Markdown
Contributor Author

Does anyone have any new ideas for resolving this? Or should we abandon it?

@ErikSchierboom

Copy link
Copy Markdown
Member

I think we should still pursue this. I have to get a diff from the existing .gitattributes files.

@ee7

ee7 commented Apr 26, 2022

Copy link
Copy Markdown
Member

Recent problem with a track that does have a .gitattributes file: exercism/java#2103

If we do this, do we also need CI to enforce that a PR does not add the wrong kind of line endings?

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.

6 participants