Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When creating the initial README.md from the project creation page, the text lines have CRLF line endings when the client is Windows, but Gitea is running in Linux #27120

Open
alexlehm opened this issue Sep 18, 2023 · 13 comments
Labels

Comments

@alexlehm
Copy link

alexlehm commented Sep 18, 2023

Description

When creating the project description README.md file, the resulting file in the git has CRLF line endings on the part the is copied from the project description, when checking out in Linux the file is still using CRLF endings since no autoconversion is used.

Gitea Version

1.20.4

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

when looking at the resulting file checked out on Linux, it looks like this:

image

Git Version

2.30.2

Operating System

ubuntu 22.04.2 LTS

How are you running Gitea?

GITEA_WORK_DIR=$PWD/data/ ./gitea web -c $PWD/etc/app.ini -p 3003

Database

sqlite

@lng2020
Copy link
Member

lng2020 commented Sep 19, 2023

The current behavior of Gitea:

  1. If you edit a file through the Gitea web editor, the CRLF will auto-translate into LF
  2. If you upload a file in Windows through the web button, the CRLF will be unchanged.
  3. If you upload a file in Windows through git, it depends on the config core.autocrlf and .gitattributes, see(https://docs.github.com/en/get-started/getting-started-with-git/configuring-git-to-handle-line-endings?platform=windows)

Related discussion (#9108)

@alexlehm
Copy link
Author

alexlehm commented Sep 19, 2023

This only happens when typing the text in the description form field, this is copied into the README.md file along with the project name and the lines from the description end up with CRLF

e.g. here. https://tildegit.org/alexlehm/test-test2

I fixed that by doing recode -f on the previous projects I created, I wonder if it would be possible to filter the description to remove the CR chars before creating the file

In fact it might work to open the README file with the web editor once and save it again to remove the CRs from the text

@lng2020
Copy link
Member

lng2020 commented Sep 19, 2023

This only happens when typing the text in the description form field, this is copied into the README.md file along with the project name and the lines from the description end up with CRLF

e.g. here. https://tildegit.org/alexlehm/test-test2

I fixed that by doing recode -f on the previous projects I created, I wonder if it would be possible to filter the description to remove the CR chars before creating the file

In fact it might work to open the README file with the web editor once and save it again to remove the CRs from the text

Well I guess the code forgets to remove the "\r" before generating the README.md file automatically. Will try to figure out and fix this one later.

@alexlehm
Copy link
Author

(the same issue is present in other forks of the software including gogs)

@silverwind
Copy link
Member

silverwind commented Sep 23, 2023

How exactly is the README generated for the issue to show? It is through this option in repo creation?

image

Is the README being edited in the web editor after repo creation?

@alexlehm
Copy link
Author

alexlehm commented Sep 23, 2023

I use Firefox in Windows and type multiple lines in the description field and create the default README.me file

image

it is not related to the web editor

@silverwind
Copy link
Member

I see. Wasn't aware we copy the description field into the generated README.

@alexlehm
Copy link
Author

the odd thing is, this feature is specific to gitea (and forks), both github and gitlab have a single-line description line that is copied into the readme which likely avoids the lineend issue

@silverwind
Copy link
Member

silverwind commented Sep 23, 2023

So I guess we could normalize to LF here which is the most common EOL format in git repos. We have no .editorconfig, .gitattributes or any other indication on which EOL preference the user has at this point, so we have to choose one format and LF seems the most likely correct one.

@alexlehm
Copy link
Author

i thought that as well, any README file will be unix format, if the user uses Windows they will usually have autocrlf active in their git config for the client

@lng2020
Copy link
Member

lng2020 commented Sep 26, 2023

image

Currently, due to the PR(#27141), the Monaco editor can auto-detect the EOL. So it won't encounter an error message even if the EOL is CRLF. That's the exactly same behavior with Github. I think it's better than changing the content silently.
Is it okay to close it now?

@silverwind
Copy link
Member

I would keep open. The textarea in repo creation sends CRLF (as all textareas do by default). I would normalize this to LF so that we don't end up with a mixed EOL file.

@lng2020
Copy link
Member

lng2020 commented Sep 26, 2023

I would normalize this to LF so that we don't end up with a mixed EOL file.

Indeed. The README.md above is a mixed EOL file but the Monaco editor just work well.
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants