Brendan Dash

Brendan Dash

windows git set eol to lf

Reason#

When writing tests for Debbl/eslint-config

await Promise.all(
  files.map(async (file) => {
    let content = await fs.readFile(join(target, file), "utf-8");
    const source = await fs.readFile(join(from, file), "utf-8");

    if (content === source) {
      content = "// unchanged\n";
    }

    await expect.soft(content).toMatchFileSnapshot(join(output, file));
  }),
);

Multiple system tests are used in the GitHub action

strategy:
  matrix:
    node: [lts/*]
    os: [ubuntu-latest, windows-latest, macos-latest]
  fail-fast: false

However, when testing on Windows, it always throws an error test, indicating that the input and output do not match. After testing, it was found that the eol in Windows default download from git is crlf

So I searched for how to set eol to lf in GitHub Action actions/checkout#135

Finally, the following command was added ci.yml

Windows can be set to lf using the following command

git config --global core.autocrlf false
git config --global core.eol lf
- name: Set git to use LF
  run: |
    git config --global core.autocrlf false
    git config --global core.eol lf

Set through .gitattributes#

* text=auto eol=lf

References#

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.