diesel-rs / diesel

A safe, extensible ORM and Query Builder for Rust

Home Page:https://diesel.rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

diesel-cli with --locked-schema fails when schema.rs has CRLF newlines

schitcrafter opened this issue · comments

Setup

Versions

  • Diesel: 2.2.2 (also works on master branch)

Problem Description

If you have a schema.rs file that uses CRLF line endings, any diesel-cli command that could change schema.rs but was supplied with --locked-schema will fail, even if the line endings are the only thing that change from what diesel-cli would output vs what's on disk. This happens as diesel-cli directly compares the generated output with the on-disk file byte-for-byte.

Particularly on windows, git might change any LF line endings to CRLF for compatability reasons, so a user that clones a repository with a schema.rs file committed will see an error when they execute diesel database reset --locked-schema, even if the schema is correct.

What is the expected output?

No error, as the generated schema matches in everything but line endings.

What is the actual output?

An error.

Are you seeing any additional errors?

No

Steps to reproduce

  • clone diesel
  • change line endings in examples/postgres/advanced-blog-cli/src/schema.rs to CRLF
  • execute cargo xtask run-tests --no-integration-tests --no-doc-tests

Workaround

Git can be told not to use CRLF line endings, changing this setting and all files in the repository can be done like this (WARNING: Will delete your local changes!):

git config --global core.autocrlf false
git rm -rf --cached .
git reset --hard HEAD