Skip to content

[FIX] Add .gitattributes so POSIX scripts stay LF on Windows clones - #2346

Open
pranayr710 wants to merge 1 commit into
CCExtractor:masterfrom
pranayr710:fix/gitattributes-lf-for-shell-scripts
Open

pranayr710 wants to merge 1 commit into
CCExtractor:masterfrom
pranayr710:fix/gitattributes-lf-for-shell-scripts

Conversation

@pranayr710

Copy link
Copy Markdown
Contributor

Fixes #2345

Reason for this PR:

  • This PR fixes a bug that I have personally experienced (it broke my own Docker build) and which reproduces from a clean clone in three commands.

Sanity check:

  • I have read and understood the contributors guide.
  • I have checked that another pull request for this purpose does not exist.
  • Bug fix, so NOT added to the changelog.
  • Not adding new C code.

What was wrong

There is no .gitattributes in the tree. Git for Windows defaults to core.autocrlf=true, so a clone made on Windows gets CRLF in every text file — including the shebang of all 16 POSIX shell scripts. docker/Dockerfile runs RUN ./pre-build.sh, and that fails:

/usr/bin/env: 'bash\r': No such file or directory
ERROR: process "/bin/sh -c ./pre-build.sh" did not complete successfully: exit code: 127

CONTRIBUTING.md asks for "Unix line endings" but nothing enforces it.

Before / after

Clone with Git's default Windows setting, then run the project's own pre-build step under Linux:

clone of linux/pre-build.sh ./pre-build.sh
master CRLF line terminators exit 127
this branch LF exit 0
# before
git -c core.autocrlf=true clone --depth 1 https://github.com/CCExtractor/ccextractor.git
docker run --rm -v $PWD/ccextractor:/src -w /src/linux debian:bookworm-slim \
    sh -c './pre-build.sh; echo exit=$?'
#   /usr/bin/env: 'bash\r': No such file or directory
#   exit=127

Scope

Deliberately narrow — no * text=auto. 978 tracked files are currently committed with CRLF (Visual Studio project files and similar), so a blanket rule would renormalise the whole repo and bury this fix in noise. The rules here name only POSIX scripts (eol=lf) and Windows scripts (eol=crlf).

I verified with git add --renormalize . that adding this file changes no tracked file's content: the commit is the new file and nothing else.

The *.bat / *.ps1 lines are the mirror case and are a no-op today (those files are already CRLF); they are there so the inverse problem cannot appear later. Happy to drop them if you'd rather keep the file to the LF half.

Git for Windows defaults to core.autocrlf=true, which rewrites LF to CRLF
on checkout. The tree has no .gitattributes, so nothing stops that from
reaching the shebang of every POSIX script, and a clone made on Windows
cannot run the build documented in docs/COMPILATION.MD or the
local-source Docker build in docker/README.md:

    $ ./pre-build.sh
    /usr/bin/env: 'bash\r': No such file or directory
    exit=127

Pin the shell scripts to LF, and the Windows batch/PowerShell scripts to
CRLF, on every platform.

Deliberately narrow: no "* text=auto". 978 tracked files are committed
with CRLF and normalising them would be a repo-wide rewrite unrelated to
this fix. Verified that adding this file changes no tracked content.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant