Closed sanjeevsree closed 2 years ago
What are the differences? Have you run git diff
to check? Could it be a misconfiguration of git for handling end of lines?
The git diff shows no change but it is time-consuming effort to provide yes or no input for all the files which it asks for overwriting
Can you provide more details on conflicting file types? Have you modified generated .gitattributes
?
When i try modifying an entity in windows it asks for overwriting all files for all entities
I also encountered the problem during entity generation, the cause seems to be that line ending differences (LF vs. CRLF) are treated by JHipster as conflicts while checking the existing files.
So I think it is related to git configuration
Not necessarily. Forcing LF line endings in Git does make the problem go away, but that is only a workaround in my opinion. The real problem here is that the JHipster generator wants to create code with LF line endings regardless of the OS it runs on.
The fix would be something like this:
const convertToCRLF = () =>
patternSpy(file => {
file.contents = file.contents.replace(/!\r\n/g, '\r\n\');
}, '**/*.java').name('jhipster:crlf');
And inject
...(isWindowsOs ? [convertToCRLF()] : []),
The generator exists since more than 5 years, and as far as I remember, we don't have this kind of problem.
Adding this work around can change all projects of our Windows users.
Adding a new question / flag would be over killed.
@pascalgrimaud, JHipster actually had similar issues already (see https://github.com/jhipster/generator-jhipster/issues/11231 and https://github.com/jhipster/generator-jhipster/pull/11205). Maybe the previous fix broke somehow?
Updated fix:
const convertToCRLF = git =>
patternSpy(async file => {
const result = await git.raw('check-attr', 'eol', '--', file.name);
if (result.includes('crlf') {
file.contents = file.contents.replace(/!\r\n/g, '\r\n\');
}
}, '*').name('jhipster:crlf');
And inject
...(isWindowsOs ? [convertToCRLF(this.createGit())] : []),
And change
https://github.com/jhipster/generator-jhipster/blob/78f3624e66d1a12c0a45715e557bb2d26e8b59e5/generators/bootstrap/index.js#L104
to include .gitattributes
so it will be committed to disk before using it.
@mshima being on Windows does not mean that we want files to be generated with CRLF. When git core.autocrlf
is false
, LF files are not automatically transformed to CRLF and I think it's better when everyone use LF both remotely and locally to avoid that kind of issue.
I did not check what have been done in the past to handle that in generator-jhipster, my 2 cents.
The specific problem mentioned by @sanjeevsree seems to be caused by either having remote CRLF files (which is not advisable) or local CRLF files (which is not compatible with JHipster generated files, apparently).
IMHO the best workaround would be to fix her/his own local configuration and/or remote files, instead of making JHipster force CRLF for all Windows users, ignoring their git configuration, which is an opinionated "breaking" change.
In JHipster Lite, we now detect line endings used in the project to see if it needs CRLF, and it defaults to LF.
The simplest thing would be to recommend using LF in the README :)
Both git and jhipster do one similar task and this is creating brand new files on target OS. Git does the job well so why jhipster shouldn't? I think solution by https://github.com/jhipster/generator-jhipster/issues/17115#issuecomment-986118493 is a nice compromise.
Git persists files with LF. JHipster generates files with LF. Most IDEs can edit files with LF on Windows, but that must be configured.
Changing JHipster generator to be aware of the OS and generate CRLF for Windows and LF for everything else would actually solve a problem of extra configuration needed on Windows to use LF for all files that JHipster generates. But on the other hand the only place you might need CRLF on windows are BAT files or other scripts that are required to have CRLF by Windows. Also most application apart from your heavyweight smart IDE will try to render CRLF on Windows and when just LF is found it might introduce a problem. That's why git implemented its detection algorithm to checkout files correctly on Windows that can be also fine tuned in .gitignore file.
Hi,
I know this topic is quite old but I'm having said problem right now.
As JHipster thinks it has to regenerate everything even I just add a field to one entity, probably because of git wrote the files with CRLF on checkout, I tried to stick with LF.
However Eclipse changes half of the files back to CRLF when the Maven Builder is triggered despite I configured the workspace to use LF.
So that ofcourse leads again to unstaged non-changes, JH regenerating the not really changed files again etc.
Can anyone give me a hint how to cope with that? :D Do I really have to apply dos2unix to all changed files before firing up the JHipster generator again? What happened to @mshima's PR, using JH 8 beta 3 it doesn't seem to be there at least.
Best Martin
@mbrandl87 the transform is there: https://github.com/jhipster/generator-jhipster/blob/f8a926b6cb854679278026a784db57edd28670a8/generators/bootstrap/generator.mts#L191
You should open a new issue if it’s not working.
All the entities are re-generated again when I run my code after switching my OS from mac to windows.
I tried to update a single entity using jdl. It works fine in mac whereas when I try the same in windows environment all the entities are getting regenerated again.
I am getting that the entities are identical in my mac system but it is asking to be overwritten in windows.
Tried running inside an Ubuntu container but the result is the same. This causes a lot of change files in git and makes the development slow
jhipster version: 7.3.1