Skip to content

fix: add .gitattributes to enforce LF line endings for Go files#483

Merged
Aureliolo merged 3 commits intomainfrom
fix/gitattributes-lf-go-files
Mar 16, 2026
Merged

fix: add .gitattributes to enforce LF line endings for Go files#483
Aureliolo merged 3 commits intomainfrom
fix/gitattributes-lf-go-files

Conversation

@Aureliolo
Copy link
Copy Markdown
Owner

@Aureliolo Aureliolo commented Mar 16, 2026

Summary

  • Add .gitattributes to force *.go and *.sh files to use LF line endings in the working tree, regardless of core.autocrlf setting
  • Fixes recurring golangci-lint gofmt failures on Windows (especially in worktrees) caused by CRLF conversion

Root Cause

core.autocrlf=true (Windows default) converts LF→CRLF on checkout. Go tooling (gofmt/golangci-lint) treats CRLF as a formatting error. Worktrees are worst affected since every file gets a fresh checkout — all 22 Go files with CRLF were flagged.

Test plan

  • Verified golangci-lint run passes (0 issues) after applying .gitattributes
  • Verified gofmt -l . reports no files
  • Verified all Go files now have w/lf in git ls-files --eol output
  • Verify CI golangci-lint job passes
  • Verify worktree checkout produces LF line endings for Go files

core.autocrlf=true on Windows converts LF→CRLF on checkout, causing
golangci-lint gofmt checks to fail with spurious "not properly formatted"
errors. Worktrees are worst affected since every file gets a fresh checkout.

Force *.go and *.sh to always use LF in the working tree regardless of
the user's autocrlf setting.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 16, 2026

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a .gitattributes file to standardize line endings for Go and shell script files. This change is crucial for maintaining consistent code formatting across different operating systems, especially Windows, where Git's default core.autocrlf setting can lead to CRLF conversions that cause Go tooling to report formatting errors. By enforcing LF line endings, the PR prevents build failures and ensures a smoother development experience.

Highlights

  • Line Ending Enforcement: Added a .gitattributes file to explicitly force *.go and *.sh files to use LF (Line Feed) line endings in the working tree. This overrides the core.autocrlf setting, which can cause issues on Windows.
  • Gofmt/Golangci-lint Fix: Resolved recurring golangci-lint and gofmt failures on Windows, particularly in Git worktrees, which were caused by CRLF (Carriage Return Line Feed) conversions.
Changelog
  • .gitattributes
    • Added a new file to define Git attributes for line ending normalization.
Activity
  • The author, Aureliolo, created this pull request to address line ending inconsistencies affecting Go tooling on Windows.
  • The author has provided a detailed summary, root cause analysis, and a test plan, including verification steps for golangci-lint, gofmt, and git ls-files --eol output.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 37314230-46a9-452d-8ccf-95dc3ba43918

📥 Commits

Reviewing files that changed from the base of the PR and between f628ac7 and 595f426.

📒 Files selected for processing (1)
  • .gitattributes
📜 Recent review details
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: CR
Repo: Aureliolo/synthorg PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-03-15T11:48:14.867Z
Learning: Pre-commit hooks: trailing-whitespace, end-of-file-fixer, check-yaml, check-toml, check-json, check-merge-conflict, check-added-large-files, no-commit-to-branch (main), ruff check+format, gitleaks, hadolint (Dockerfile linting).
📚 Learning: 2026-03-15T11:48:14.867Z
Learnt from: CR
Repo: Aureliolo/synthorg PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-03-15T11:48:14.867Z
Learning: Pre-commit hooks: trailing-whitespace, end-of-file-fixer, check-yaml, check-toml, check-json, check-merge-conflict, check-added-large-files, no-commit-to-branch (main), ruff check+format, gitleaks, hadolint (Dockerfile linting).

Applied to files:

  • .gitattributes
🔇 Additional comments (4)
.gitattributes (4)

1-6: Good root-cause fix for Go formatting drift on Windows.

This correctly enforces LF for Go/tooling-critical files and should prevent recurring gofmt/golangci-lint false failures from checkout conversion.


8-11: Template and golden-test normalization is well scoped.

Enforcing LF here is a solid reliability guard for deterministic test fixtures and rendered output comparisons.


13-17: LF enforcement for shell and Docker is correct and practical.

These rules reduce cross-platform breakage in script execution and container build contexts.


19-20: PowerShell exception is appropriate.

Keeping *.ps1 on CRLF while normalizing the rest to LF is a clean cross-platform balance.


📝 Walkthrough

Summary by CodeRabbit

  • Chores
    • Updated repository configuration to ensure consistent code formatting standards across all project files.

Walkthrough

Adds a new .gitattributes file that enforces LF (eol=lf) for Go, Go module files, templates, shell scripts, Dockerfiles and YAML testdata, while preserving CRLF (eol=crlf) for PowerShell scripts.

Changes

Cohort / File(s) Summary
Git attributes
/.gitattributes
Adds eol=lf for *.go, go.mod, go.sum, *.tmpl, cli/testdata/**/*.yml, *.sh, Dockerfile; sets eol=crlf for *.ps1.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a .gitattributes file to enforce LF line endings for Go files, which is the primary purpose of this PR.
Description check ✅ Passed The description is directly related to the changeset, providing clear context about the .gitattributes addition, root cause of line ending issues, and verification steps already completed.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/gitattributes-lf-go-files
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/gitattributes-lf-go-files
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds a .gitattributes file to enforce LF line endings for Go and shell script files. My review includes a suggestion to expand this configuration to cover other relevant file types (go.mod, go.sum, .ps1) and to set a recommended default for all text files, making the approach more robust.

Comment on lines +1 to +7
# Go tooling (gofmt, golangci-lint) requires LF line endings.
# Without this, core.autocrlf=true on Windows converts to CRLF on checkout,
# causing spurious "not properly formatted" errors — especially in worktrees.
*.go text eol=lf

# Shell scripts must use LF (bash can't parse CRLF).
*.sh text eol=lf
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This is a good start for ensuring consistent line endings. To make it more comprehensive, I suggest a few additions:

  1. Add * text=auto: This is a recommended best practice. It tells Git to automatically handle line endings for any file it detects as text, which prevents files from being accidentally treated as binary.
  2. Include go.mod and go.sum: These files are also managed by Go tooling and can cause issues if they have inconsistent line endings. It's best to enforce LF for them as well.
  3. Include *.ps1: For consistency with other scripts (.sh), it's a good idea to enforce LF for PowerShell scripts too.

Here is a suggested update that incorporates these points.

# Auto-detect text files and normalize line endings.
* text=auto

# Enforce LF for Go-related files.
*.go text eol=lf
go.mod text eol=lf
go.sum text eol=lf

# Enforce LF for scripts.
*.sh text eol=lf
*.ps1 text eol=lf

coderabbitai[bot]
coderabbitai bot previously approved these changes Mar 16, 2026
…olden tests

Address review feedback from infra-reviewer, Gemini, and CodeRabbit:
- Add Dockerfile LF rule (CRLF breaks shell continuations in Linux containers)
- Add *.tmpl and cli/testdata/**/*.yml LF rules (golden test comparisons)
- Add go.mod/go.sum LF rules (Go tooling consistency)
- Add *.ps1 CRLF rule (PowerShell expects CRLF on Windows)
@Aureliolo Aureliolo merged commit 1b8c7b6 into main Mar 16, 2026
23 checks passed
@Aureliolo Aureliolo deleted the fix/gitattributes-lf-go-files branch March 16, 2026 07:36
Aureliolo added a commit that referenced this pull request Mar 16, 2026
🤖 I have created a release *beep* *boop*
---


##
[0.2.8](v0.2.7...v0.2.8)
(2026-03-16)


### Features

* add RRF rank fusion to memory ranking
([#478](#478))
([42242b5](42242b5))
* collaboration scoring enhancements — LLM sampling and human override
([#477](#477))
([b3f3330](b3f3330))


### Bug Fixes

* add .gitattributes to enforce LF line endings for Go files
([#483](#483))
([1b8c7b6](1b8c7b6))
* **cli:** Windows uninstall, update UX, health check, sigstore
([#476](#476))
([470ca72](470ca72))


### Refactoring

* **web:** extract WebSocket subscription into reusable composable
([#475](#475))
([96e6c46](96e6c46)),
closes [#351](#351)


### Maintenance

* bump hypothesis from 6.151.5 to 6.151.9 in the minor-and-patch group
([#482](#482))
([a7297d5](a7297d5))
* bump nginxinc/nginx-unprivileged from `aec540f` to `ccbac1a` in
/docker/web ([#479](#479))
([176e052](176e052))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

1 participant