Skip to content

file upload doesn't respect .gitattributes to normalize CRLF line endings #17496

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

Open
plgruener opened this issue Oct 30, 2021 · 2 comments
Open

Comments

@plgruener
Copy link

Gitea Version

1.16.0+dev-444-g40c8451b7

Git Version

No response

Operating System

No response

How are you running Gitea?

Tested via https://try.gitea.io/plgruener/testCRLF

Database

No response

Can you reproduce the bug on the Gitea demo site?

Yes

Log Gist

No response

Description

In a Git repo with a .gitattributes file with contents * text=auto, all newly added/staged files have their line terminators automatically converted from CRLF -> LF.
However, when you upload and commit a file with CRLF line terminators via the Gitea webinterface, the line endings are not normalized.

You can see this when you clone the example repo: crlf.txt was given CRLF (with the unix2dos utility) and uploaded via "upload file".
(Be careful to not enable core.autocrlf in your local Git config; and set core.eol=lf, else Git will convert every file to CRLF line endings.)
Also when you edit the example file again with the web editor (which forces LF line endings), you'll see that it reports seemingly identical changes on every line, indicating a line ending conversion.

(When copy-pasting the text in the "new file" web-editor, this is not immediately an issue, because the web editor forces LF line endings. But ideally, the editor should also respect .gitattributes, see #9108.)

Expected behaviour: be able to force the line ending style on all files by respecting the .gitattributes, whether they are submitted by push, by web-editor or by uploading a file.
If there's a workaround to just force LF on upload, that would be fine, but keep in mind that some files on Windows, eg .bat scripts, may require CRLF.

Screenshots

No response

@baltitenger
Copy link
Contributor

This issue also affects lfs: it will add the files to git when they should be added to lfs instead, according to .gitattributes.

@zeripath
Copy link
Contributor

zeripath commented Jan 15, 2022

This issue is not about lfs - if you're certain that you have lfs running have the gitatrributes committed on the branch you're uploading to and you're definitely sure this should be applying then reopen a new issue giving all of the correct details.

This should be working on 1.16:

var filename2attribute2info map[string]map[string]string
if setting.LFS.StartServer {
filename2attribute2info, err = t.gitRepo.CheckAttribute(git.CheckAttributeOpts{
Attributes: []string{"filter"},
Filenames: names,
})
if err != nil {
return err
}
}
// Copy uploaded files into repository.
for i := range infos {
if err := copyUploadedLFSFileIntoRepository(&infos[i], filename2attribute2info, t, opts.TreePath); err != nil {
return err
}
}

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

No branches or pull requests

3 participants