jesseduffield / lazygit

simple terminal UI for git commands
MIT License
51.82k stars 1.82k forks source link

feature: Wrap commit body at 72 characters #2627

Closed jalil-salame closed 6 months ago

jalil-salame commented 1 year ago

Is your feature request related to a problem? Please describe. I recently had some issues where I had to amend commits because their format was wrong; it was expected for the body to wrap at 72 characters.

Describe the solution you'd like I would like the body of a multiline commit to warp at 72 characters.

Describe alternatives you've considered

Additional context

stefanhaller commented 1 year ago

Wrapping lines automatically is not a good idea, I think. This might work for simple paragraphs, but we often have commit messages containing e.g. markdown bullet point lists or other "half-formatted" text, and it's very hard to come up with an automatic wrapping algorithm that doesn't mess these up.

A git hook to reject long lines is good, we have one at work.

What I usually do is "commit with editor" and then use whatever wrapping functionality is built in to the editor I'm using (e.g. Alt-Q on emacs). I don't think it's worth adding such functionality to lazygit's commit editor; it will never be nearly as powerful as a dedicated text editor.

It might, however, be useful to do something simple and draw a ruler at 72 characters so that you can see how long the lines are allowed to be. It would have to be configurable though, I want it at 80. 😄

jesseduffield commented 1 year ago

I like the idea of a ruler. I suspect it would be pretty straight-forward to implement

stefanhaller commented 1 year ago

I would have no idea how to go about it, to be honest. Any pointers?

mark2185 commented 1 year ago

Just pointing out that a PR was in the works for something like that.

jalil-salame commented 1 year ago

Just pointing out that a PR was in the works for something like that.

This issue should probably be split into add a marker at X characters and wrap commit body at X characters, the sentiment appears to be that warping should be closed a won't fix or help wanted.

That way they don't overlap

aubreypwd commented 1 year ago

Wrapping

It would also be nice to have an option we can set that will simply wrap the message where the box ends. It will still commit a long line, but the box itself will wrap. That way I can see my entire message.

CleanShot 2023-08-23 at 10 08 23@2x

⬆️ you can see I can't really see what I typed.

CleanShot 2023-08-23 at 10 09 11@2x

Ideally it would wrap the word, but the character would also be fine. Again, the commit message here in the reflog would be:

Update Rates to be affiliates with Affiliates

A Rate, before this commit, belonged to "Rates" but that isn't accurate, it should belong to Affiliates since they are the one's who have rates.

...without a break.

Rulers

I also think Ruler settings would also be appropriate, we would need 2 (or more?):

One for subject, and one for the description.

stefanhaller commented 1 year ago

It will still commit a long line, but the box itself will wrap.

I don't think this is desirable. It would encourage people to create commit messages with long lines, which is not a good idea. Commit messages should really be hard-wrapped so that they are readable on any git client.

I also think Ruler settings would also be appropriate, we would need 2 (or more?): One for subject, and one for the description.

The subject already has a count for how many characters have been typed so far, so I don't think it needs a ruler. Only the body does.

jwhitley commented 9 months ago

In line with @stefanhaller's and @aubreypwd's comments, I think a rule at column 72 is probably ideal as a first step, but I'd take a column count too. I've used git UIs that fool the user into thinking they hard-wrap, only later to discover commit messages which are unreadable in other tooling. So it's nice that lazygit is "WYSIWYG". OTOH, it's also annoying that there's zero formatting support, especially in projects that use hooks to enforce formatting rules. Once there's a column indicator, niceties like auto-word wrap at the end column could be added on top later.

stefanhaller commented 9 months ago

I disagree now. I know I argued for a ruler before, and against automatic wrapping, but I changed my mind. I started working on automatic wrapping-as-you-type (as shown here), and I won't settle for less now. 😄 For me this is the perfect solution. We shouldn't have to do any manual interactions for wrapping our text to a certain width. You don't do that when typing a paragraph in Word, either.

I hope to have something working that can be tested soon.

jwhitley commented 9 months ago

I hope to have something working that can be tested soon.

Ganbatte!

stefanhaller commented 9 months ago

Here's a draft PR: #3173. I'm very interested in feedback.

stefanhaller commented 6 months ago

Fixed by #3173.