Skip to content

Add .gitattributes to force LF line endings for shell scripts - #313

Open
Arthur Silvany (arthursilvany) wants to merge 1 commit into
microsoft:mainfrom
arthursilvany:fix/normalize-shell-script-line-endings
Open

Add .gitattributes to force LF line endings for shell scripts#313
Arthur Silvany (arthursilvany) wants to merge 1 commit into
microsoft:mainfrom
arthursilvany:fix/normalize-shell-script-line-endings

Conversation

@arthursilvany

Copy link
Copy Markdown

Problem

On Windows clones with core.autocrlf=true (the Git for Windows default), every *.sh file is checked out with CRLF line endings. Bash then fails to run the lab scripts:

scripts/setup.sh: line 19: cd: $'/mnt/c/dev/sre-agent/labs/starter-lab/scripts\r/..': No such file or directory
scripts/setup.sh: line 21: $'\r': command not found
scripts/setup.sh: line 32: syntax error near unexpected token `$'do\r''

This affects labs/starter-lab/scripts/setup.sh and the other 60+ shell scripts across labs/ and sreagent-templates/, blocking the documented lab setup flow on Windows.

Fix

Add a repository-level .gitattributes that:

  • pins *.sh, *.bash, Dockerfile, *.yml and *.yaml to eol=lf so they are always checked out with LF, regardless of the user's core.autocrlf setting;
  • keeps Windows-native scripts (*.ps1, *.cmd, *.bat) as CRLF.

Validation

After the change, on a Windows checkout:

$ bash -n labs/starter-lab/scripts/setup.sh   # exit 0

No file contents change — the blobs in the repository were already LF; only the checkout behaviour is fixed.

Windows clones with core.autocrlf=true check out *.sh with CRLF, which
makes bash fail with errors like: \$'\r': command not found and
syntax error near unexpected token \$'do\r'' when running the lab
setup scripts (e.g. labs/starter-lab/scripts/setup.sh).

Pin *.sh, *.bash, *.yml, *.yaml and Dockerfile to eol=lf, and keep
Windows-native scripts (*.ps1, *.cmd, *.bat) as CRLF.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 1b9c7a12-44cf-4dba-b696-b1106e69d4fe
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.

2 participants