dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.67k stars 1.06k forks source link

Create a dotnet-new template for .gitattributes #43764

Open MattKotsenas opened 4 hours ago

MattKotsenas commented 4 hours ago

Create a dotnet new template for .gitattributes, similar to what we already have for .gitignore and .editorconfig. Like those files, this template provides a set of best practices and basis for customization to both get a new repo up-and-running quickly and to standardize behavior for existing repos.

I started with the common template @ https://github.com/gitattributes/gitattributes/blob/master/Common.gitattributes (attribution given inline) like we do for .gitignore, then made a few changes:

1. C#-specific changes

*.cs     text diff=csharp
*.cshtml text diff=html
*.csx    text diff=csharp

This tells Git how to do diff hunk headers where there's a built-in pattern.

2. Handle .sln files

*.sln    text eol=crlf

This follows best practice used by most repos in GitHub under the dotnet organization that specify to use CRLF on checkout for VS Solution files.

3. Add a comment for CSV

# Per RFC 4180, .csv should be CRLF
*.csv      text eol=crlf

Common.gitattributes specifies to use CRLF for CSV files but doesn't specify why. I added a comment from the commit message to clarify that it's for RFC 4180 conformance.

4. Update Scripts sections comment

# Force Unix 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
...
# Likewise, force cmd and batch scripts to always use crlf

The handling of line endings for shell scripts matches between Common.gitattributes and dotnet/runtime, but I used dotnet/runtime's comments because they clarify why certain line endings are needed.

MattKotsenas commented 4 hours ago

Reviewers note: Please double-check my translations. These are find/replace from the .gitignore template; I don't know if anything further is required. Thanks!

baronfel commented 4 hours ago

For my own information - where is the diff=csharp annotation coming from? Does git know csharp natively? is there a list of maintained diff comparisons that the tooling knows about?

MattKotsenas commented 4 hours ago

For my own information - where is the diff=csharp annotation coming from? Does git know csharp natively? is there a list of maintained diff comparisons that the tooling knows about?

It does! I used this list: https://git-scm.com/docs/gitattributes#_defining_a_custom_hunk_header

This is the most up-to-date list I know of

baronfel commented 4 hours ago

Reviewers note: Please double-check my translations. These are find/replace from the .gitignore template; I don't know if anything further is required. Thanks!

I think we're not actually able to commit translations for new content at all - they just get overwritten by the translations that get pushed to us from the localization team via our automation. In any case, don't worry about it.

baronfel commented 3 hours ago

the failed tests are around commands that list all of the available template, which now includes one more. should be a quick addition.