jesseduffield / lazygit

simple terminal UI for git commands
MIT License
47.94k stars 1.72k forks source link

Fix 'go generate ./...' on windows #3708

Closed part22 closed 1 day ago

part22 commented 2 days ago

When running the go generate ./... command, pkg\cheatsheet\generate.go panics because the embedded translation files cannot be found. Previously mentionned here.

This is caused by the method filepath.Join, which uses the OS-specific path separator.

Join joins any number of path elements into a single path, separating them with an OS-specific Separator.

See filepath.Join documentation.


On Windows, it is \ (backslash). However, embed.FS.ReadFile expects the path separator to be / (slash) regardless of the OS.

The path separator is a forward slash, even on Windows systems.

See embed documentation.


To fulfill the contract of embed.FS.ReadFile, the path.Join method should be used instead since it always uses slashes as the path separator.

Join joins any number of path elements into a single path, separating them with slashes.

See path.Join documentation.


I have tried running go generate ./... on Ubuntu using WSL and the functionality seems unchanged.

Note I also ran in another problem coming from pkg\jsonschema\generate.go where it panics because the string it is looking for terminates by \n.

DocumentationCommentStart    = "<!-- START CONFIG YAML: AUTOMATICALLY GENERATED with `go generate ./..., DO NOT UPDATE MANUALLY -->\n"

However on Windows the new line characters are \r\n. The solution was to disable git autocrlf (git config core.autocrlf false) and to renomalize the files (git add --renormalize .) to have the new line character match the one in DocumentationCommentStart. It might be worth including something in the doc about how to run go generate ./....

stefanhaller commented 1 day ago

Thanks, but this is already fixed by #3705 and #3706 (which I told you about here :wink:).

part22 commented 1 day ago

Haha, yeah, I saw it too late. I'll close the PR.