microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
163.37k stars 28.93k forks source link

Git: Automatically insert line breaks in git commit messages #2718

Open stkb opened 8 years ago

stkb commented 8 years ago

I'm trying to get into the habit of writing good commit messages. Not sure if this should be the default but it would be really useful if vscode automatically wrapped commit message lines at say 80 chars and inserted line breaks.

I don't mean changing the appearance of the text in the commit message box, just before it's actually committed. The line length could be in an option too.

joaomoreno commented 8 years ago

How about a little UI that would tell you that some lines are over 80 characters, and you'd format them yourself? Would that work?

stkb commented 8 years ago

@joaomoreno Maybe, and actually that was my first thought, though these points came to mind:

Overall I felt that just inserting hard line breaks before committing would be easier, though it does mean writing or finding the code to do the word-wrapping (not sure what the policy is on using external js libraries). There could be a setting something like "git.commentLineLength" with a default 0 (no word wrap) so no-one gets any unexpected behavior.

In any case if it's wanted it is something I'm prepared to work on.

joaomoreno commented 8 years ago

Good points.

As for the UI, I was thinking something like what you get when you try to rename a file to / in the explorer. I would't use the red color but something smoother, that doesn't sound such a big alarm. I would also put it behind an enablement setting.

I would like to stay away from automatic wrapping, since it might not do what the user intends to do. Also, we'd have to make it work for non-latin languages too: Arabic, Japanese, Chinese, etc. Not a trivial task.

There's a double edge sword in automatic wrapping: turning it on by default would be transparent to the user and, if the outcome is not desirable, he will only detect that when it's too late, probably when the commit was pushed to his server. If we set it off by default, we risk that no one will find and/or use it.

What do you think?

stkb commented 8 years ago

This is an effect used in Github Desktop, as well as elsewhere.

commitmessage

Although here the effect is a bit too subtle; I find it a bit difficult to see the limit. In Twitter it's much more visible.

commitmessage2

Something between the two would be really neat, and maybe with the right balance it could be on by default.

However I don't know if the edit box is capable of that kind of rich text, so failing that, yeah the popup that comes up when entering an invalid filename is also nice and that would be ok (as you say, in a less flashy color).

arirawr commented 8 years ago

@joaomoreno Anyone working on this? I'm happy to give it a look.

joaomoreno commented 8 years ago

Actually we already have this:

image

nomicos commented 7 years ago

@joaomoreno That is a tooltip addressing the first line of the commit message. But I think the proposal described in this issue was about having Visual Studio Code automatically wrap the commit message body to 72 characters per line (the 50/72 convention). In that case, the user's only worry would be the message itself, with VSC wrapping it right after they click 'Commit' and before the actual commit is made.

stkb commented 7 years ago

@nomicos That was my original wish, yes, but as @joaomoreno pointed out, vscode has to support a lot of languages and correct automatic wrapping in non-latin languages can be really hard. (Eg in vietnamese I think they don't have spaces and you basically have to use a dictionary to know where to break the text.) It's really out of the scope of vscode.

What I now do when writing a long commit message, is compose it in blank editor and then copy-paste it in to the commit message box. I would like to see a feature that streamlined this process a bit though.

jimmyharris commented 7 years ago

I can understand how this might be beyond the scope of the editor but would it be possible to add a tooltip that tells you when you go over the 72 character length on the next line? The 50/72 commit message guideline is almost universal and it would be nice if we could follow it without the extra step of having to edit the commit message after the fact.

Alternatively is there a reason we couldn't make the commit message window more like an editor window? There are plugins for automated line wrapping that currently cannot be accessed in the commit message window. It would be excellent if we could access them inside the commit message window.

medikoo commented 7 years ago

@stkb @joaomoreno

vscode has to support a lot of languages and correct automatic wrapping in non-latin languages can be really hard.

I think it would be totally ok if it'll work purely with spaces as we use them writing English.

Programming and writing commit messages in English is common approach worldwide, no matter where are you from, and what is your native language. So providing support for all written languages in that specific case seems an overkill.

joaomoreno commented 7 years ago

From @rmunn


I'm asking for #2718 to be reopened, or for further discussion on the feature to be had in this issue. #2718 was closed because wrapping arbitrary-language text is really difficult (e.g., Thai has no spaces between words, and there is no algorithmic way to correctly break lines in between words; you have to have a Thai dictionary built into your program if you want correct linebreaks in Thai). However, there are two factors that make this an unimportant consideration for Git commit messages:

  1. Any programming team that has more than one native language among the programmers in the team has probably already standardized on a single language, and that language is almost always English where spaces between words are normal.

  2. There are very good reasons for NOT splitting lines in commit messages if those lines do not contain spaces, because those lines are probably URLs.

So the rule for Git commit message word wrapping should be very simple:

  1. First line warns if it's more than 50 columns. (This is the current behavior).
  2. Second line warns if it isn't blank.
  3. Rest of the commit wraps on spaces (or on any whitespace, but I recommend sticking with plain 0x20 space characters only for simplicity) at a user-configurable column, defaulting to 72 since that's the current standard recommended by Git.
  4. Any line in the commit that does NOT contain spaces does not wrap, but a warning pops up (similar to the warning if the first line is > 50 columns) saying "Your commit message contains # long line(s) which could not be wrapped because they do not contain spaces. If these lines are URLs, that's probably okay, but otherwise you should consider adding spaces so that the lines can be wrapped. Your settings are currently set to wrap any lines longer than 72 characters in your commit message." (With #, of course, being substituted for the actual number of too-long lines in the message.)
  5. That warning can be disabled in the user or workspace config settings, for the sake of any teams who have standardized on languages like Thai which do not use spaces in the language. The word-wrapping behavior can also be completely disabled if the user so desires, but it starts configured to be ON.
  6. (Optional). If the long line starts with the regex [a-zA-Z][-a-zA-Z+.]+: (see RFC 3986), it is assumed to be a URL and no warning is issued for that line, since it's usually not desirable to split a URL across two or more lines.

This would go a long way towards making VS Code's Git message editor usable. As of right now, I avoid using VS Code's Git integration because it doesn't format Git messages correctly according to the coding standards of just about every project I've worked on. So despite the fact that VS Code has pretty good Git integration for most things, I still just Alt-Tab to a terminal and write my Git commits in Vim, where I can set it up to do the right thing for commit messages (wrap at 72 columns, or at 70 for one project I work on that has slightly stricter rules than most).

P.S. Also, as a side effect, I'd like to ask that the Git commit window NOT visually wrap lines that aren't truly wrapped (e.g., the only thing that causes text to go to the next line in the commit window is a real linefeed or CR/LF in the commit message). Instead, if the text goes past the end of the available window size, give us a horizontal scrollbar, which will serve as a cue to resize the Git sidebar to be large enough to fit 72 characters horizontally. And perhaps also there could a button that will automatically resize the Git sidebar to fit the text already in the commit message -- though that's a more "bells and whistles" feature, rather than core functionality.

rmunn commented 7 years ago

Note that my proposal is close to what @stkb originally asked for when he opened this feature request, but there is one specific part of my proposal that is the opposite of what he asked for. He said he wanted the appearance of the Git commit message window to not change, and for the returns or linefeeds to be inserted ("silently", so to speak) after the message composition is finished. Whereas what I am proposing is that the wrapping be visually obvious, so that it's clear precisely where your text is going to be wrapped. This is basically a different proposal, which is why I originally opened a new issue to track it. But we might as well discuss it here, where interested people are already subscribed.

e-segev commented 7 years ago

VS Code version 1.14.2

I think the commit message box is terrible and very limiting for such an important feature (entering detailed message, that is) and renders the integrated GIT unusable for me.

I use Sublime instead, where a text file is opened and I may enter conveniently a detailed message in any format I wish.

I'm not sure why it is difficult to do the same here.

TrevorBurnham commented 7 years ago

@eaz120 I've requested this feature at #30562.

stkb commented 7 years ago

Closing this now as the original query has been answered, and I agree an easy way to write commit messages in a full editor would be better.

medikoo commented 7 years ago

Closing this now as the original query has been answered

@stkb since which version it's in VS Code? On my side I actually don't see that feature.

stkb commented 7 years ago

@medikoo It was answered in the sense that vscode now gives a warning if the message is too long and it was explained why automatic wrapping was too problematic to implement.

Since I see from upthread that you disagree with that, I've re-opened.

medikoo commented 7 years ago

@stkb yes, just warning doesn't help much and real solution is definitely possible. Great thanks for reopening

xogeny commented 6 years ago

Just a comment (since this is still open). I've actually been quite frustrated by the commit message box in VSCode. I'm surprised more people aren't commenting on this, but it really does seem odd that commit messages are edited in a sidebar. I understand auto-wrap may be problematic in some languages, but couldn't you just disable it for those language? It seems a bit strange to not implement a feature that the vast majority of users would benefit from just because some wouldn't. But in any case, just something that visually indicates overstepping the 72 character convention would be useful. I saw this this and thought, "Perfect! And it doesn't matter to me if it is implemented as an extension." only to realize that that is an extension for Visual Studio, not Visual Studio Code.

Bottom line: I agree that this is a frustrating aspects of an otherwise excellent editor.

pkazmier commented 6 years ago

@xogeny Agreed, we should not be using the sidebar for commit messages. I’m floored that there isn’t as much noise about the integrated Git commit message box or the fact that lines aren’t wrapped. Like others, I can’t use VScode to commit as every project I’m on has rules on line length.

The irony of the situation is that we haven’t found a good solution on how to edit a Git commit message in the world’s best editor!

stkb commented 6 years ago

As I've said above, I'd like this to be simplified, but really it's easy enough to commit from the integrated terminal so that it opens a 2nd instance of vscode where you can do all the formatting and wrapping you like. I only use the sidebar for very quick/temporary commit messages.

mbiegert commented 6 years ago

As multiple others are "floored" by the low noise here, I'd like to add my two cents here: As @stkb pointed out the integrated commit box is really useful for quick commits containing only a few words. However, as it is recommended to write detailed commit messages, the tiny commit box on the left pane does not seem fit for this purpose. Even if it would hard break the lines as suggested in the original post. On the other hand I very much like the git pane: It helps in staging the right files, review your changes, etc. I'd therefore vote for streamlininge the workflow @stkb seems to have established for himself: Upon committing with an empty commit message (using the checkmark in the git pane) an editor window in vscode should open where you can write your commit and which automatically (and visually) wraps your lines as you type the text.

xogeny commented 6 years ago

@mbiegert I agree. Even though I am quite proficient with the git command line, like you I really like the sidebar. It is just the treatment given to the commit message I'm disappointed by.

An approach that opens a tab in the editor for the commit message would be fine for me.

Another idea which I failed to mention in my previous post. What if the Git pane resized itself when the commit message had focus? That way, the Git pane would be minimal and sit nicely on the side when you were looking at code, comparing things, etc. But the moment you actually focus on the commit message it expands to something that can accommodate the 50/72 rule? Then, when the commit has been made or focus has been dropped, it returns to its previous size.

It seems so simple, it almost makes me want to write it as an extension. But never having written a VSCode extension before and being too busy at the moment, I'll have to defer that for now. 😞

acdha commented 6 years ago

This seems a lot more useful now that the commit dialog will nag about long lines but doesn't offer any way to fix the message except manually wrapping the text yourself. I end up using vim in a terminal window since the experience is so much better.

oliversalzburg commented 6 years ago

I end up using vim in a terminal window since the experience is so much better.

That pretty much sums it up for me as well.

jkodroff commented 6 years ago

Would like to put in my two cents if I may. Here's how I would design the commit inputs (moving from a single textbox to 2 separate inputs:

  1. Textbox
    • Required
    • Hint: Enter a summary of your commit here
    • Max length 50 with inline character counter
  2. Textarea
    • Optional
    • Hint: Enter more detailed explanatory text if necessary. Use blank lines to break paragraphs. Use hyphens for bullet points
    • Automatically (forcibly) wraps content at 72 characters per line

Optionally include a link to detailed guidelines for good git commit messages, e.g. https://gist.github.com/robertpainsi/b632364184e70900af4ab688decf6f53

Optionally include an option to go back to the old single input textbox since people get upset when you move their cheese, possibly to be removed eventually.

I think the UI I describe above should be the default as we want to steer users towards writing quality commit messages.

Apologies in advance for my ignorance of a11y, i18n concerns as well as the capabilities of Code's UI components - I'm just a regular old user with a feature request.

The main use case I'm thinking of is that I recommend Code to ops folks who are brand new to infrastructure as code. Many of them have never used an IDE/fancy text editor at all, let alone git. So in order to get them writing good commit messages, I have to advise them to install an additional tool (Sourcetree, GH Desktop, or similar) in order to make it easy for them to write good commit messages.

JerkyTreats commented 6 years ago

Hey sorry if this has already been discussed, this thread is long in the tooth.

screen shot 2018-03-28 at 1 56 45 pm

Can we make the commit body not warn for line length, or better yet make it optional? I only care about the first line being too long, latter lines Im fine with.

tstivers1990 commented 6 years ago

Perhaps this should go in a separate issue. But I feel the commit textbox should be using monospace font by default as well. This would allow for adding a ruler to the box as an additional option.

medikoo commented 6 years ago

Generally it should probably work as:

I still wonder why it's so hard to autobreak, afaik some other editors do it well.

madig commented 6 years ago

Atom breaks lines by itself by default in recent versions, you can turn that off by clicking a small icon in the commit text field. This would be nice to have.

HookyQR commented 6 years ago

My preference:

  1. Commit message box renders in fixed width font (the user's editor font would be perfect)
  2. Same warning exists for first line.
  3. Window shows a (optional) ruler at the 72 character point. (or a settable value)
  4. I can take or leave the 72 character warning, because it doesn't tell me what character I'm at anyway, so finding the right point to go back and hit enter is annoying.
ssbarnea commented 6 years ago

Is there a way to enforce the 50/72 rule with vscode? Somehow I have the impression that if you setup vscode as your git editor, it would break well formatted messages by auto-unwrapping the message.

waynew commented 6 years ago

Is it possible to just have a setting "auto wrap git commit messages"?

That would solve the problem of breaking behavior when committing in non-ascii text, as well as allow the rest of the world to have the behavior they want. Win win?

I would turn that on right now if it existed. Ship by default with it off (or maybe use LANG to see if it's en_ something and turn it on).

Personally, I'd probably just want a warning on the first line, I'd love for it to force a blank second line, and then wrap the other lines at spaces if there's more than 72 characters.

In my dream, I'm typing my summary and I hit 50 characters it would give me a warning like it does right now for the 72 lines, so I can decide if I want to keep with the limit or maybe I have a darn good reason.

Then I hit enter and I simply cannot edit the second line (or maybe make the UI like GitHub's, with a separate box). Then I start typing in the next box and as soon as I hit 72 characters it goes back to the previous space and puts a newline there instead. Then I type a bit more and paste in a URL, and then it doesn't wrap that one, because it's a URL and it's long because the Internet.

But I hit space and start typing and it drops to the next line, and I finish up and then I'm done and hit ctrl+enter and it submits my commit like it always does.

Any questions?

iancanderson commented 6 years ago

What @waynew describes is exactly what I want and expect (warning for commit "title", auto-wrapping for description)

JamesYFC commented 5 years ago

Warning-wise, it seems like we used to have the 50 part of the "50/72 rule", and now we only have the 72 part. The first line now only warns at 72 chars, not 50 -- at least on the windows version.

image

This doubles as a mini warning for anyone else who quickly control-backspaces after seeing the warning without reading it, while assuming that it hasn't changed from 50 characters, like I did...

fatcerberus commented 5 years ago

The current warning is nice to have, but I find it kind of annoying since it just tells you you're X characters over the limit without actually showing you where the line break should have gone. This makes for a lot of wasted time after I've typed almost a whole sentence before noticing the warning and now have to figure out by trial and error where I should put the line break...

The ideal solution for me would be just to allow me to type a message "naturally", using soft wrapping only (which also makes it easier to review before submitting) and apply the 72-column hard wrap automatically when actually making the commit. This is what the old version of GitHub Desktop used to do and a feature I really miss in their new client.

Peeja commented 5 years ago

This is also what magit does by default. (Or rather, it adds hard breaks as you go, but the end result is that you don't have to work for it.)

Kinrany commented 4 years ago

For me the biggest pain is that the "X characters over 72" warning is hard to predict. This breaks my flow. With a ruler I would insert newlines on the fly, but right now I have to stop typing and go back to fix the warning.

Resizing the sidebar to be 72 characters wide would be an acceptable makeshift solution, but the font is not monospaced.

adab4d commented 4 years ago

For me the biggest pain is that the "X characters over 72" warning is hard to predict. This breaks my flow. With a ruler I would insert newlines on the fly, but right now I have to stop typing and go back to fix the warning. Resizing the sidebar to be 72 characters wide would be an acceptable makeshift solution, but the font is not monospaced.

I create a new window on the fly, switch the language to git-commit and write there the message. In settings.json I have:

  "[git-commit]": {
    "editor.rulers": [
      50,
      72
    ]
  },

This breaks the flows a bit as well but I prefer having visual guidance.

CombeeMike commented 4 years ago

I'm also having struggle with the max length in the commit editor. What I'd like to see is short & simple:

This would improve the "write commit message" experience quite tremendously for me!

Edit

I've created a dedicated issue #93150 since I felt that the request is not "well placed" here...

VeteranCoder commented 4 years ago

Hello everybody. Since this issue remains open, I'd like to throw in my observations and a suggestion.

I generally don't commit with VS Code precisely because of this input box. It leaves me unsure of the appearance of the end result when viewed online or in another IDE. I'd like the box to accurately reflect the format, and perhaps expand automatically while editing to look more like a typical editor.

I usually use GitEye for all my repository work for several reasons (and the list shrinks as integrations improve).

First, I have a full-screen view of the state of my repository, its layout is pleasing, and I get a "visual" sense of the state of my branches, history, and pending work. Second, it is written in Java so I can use it on Windows and Linux. Third (and the part relevant here), is the "Git Files" view - specifically the commit message box.

It warns when there is no empty line after first, but doesn't have a separate wrap length from the rest of the text. The example below is a single line of text pasted into the editor. I added only a linefeed after the first line. Wrapping is automatic, and a grey line identifies the wrap point. When committed, the text looks exactly as it did when writing it.

If the panel is narrower than the wrap, it will wrap the lines in the editor, then break at the proper location, so it doesn't look great. Simply widening the view automatically gets it to what is shown below. This is an open-source project, so developers here might want to take a look at the code and see if it can be translated to VS Code in a useful way.

giteye-files-view

elieux commented 4 years ago

We can now set monospace font in v1.46.

austinorth commented 3 years ago

I would just like to chime in here to echo @waynew . I have been automatically wrapping the body of my commit message to keep lines at 72 characters or less when I author a commit in terminal, and it makes things quick and easy. I don't have to think about what word I'm going to put on the previous line as opposed to the next line. This is a small calculation that I really never want to ever have to think about. As a newer user of VSCode, it was jarring to me that this functionality doesn't exist! 😞 So it would be so nice to just have a lil' setting that allowed you to turn this on. 🙏🏻

aradalvand commented 2 years ago

No updates on this one?

lszomoru commented 2 years ago

There is currently a pull request which would add the capability to use the editor for authoring a commit message. The pull request leverages some vscode API that is currently being finalised but as soon as that happens we should be able to make progress on the pull request.

marcusrbrown commented 2 years ago

I noticed the PR was merged a few days ago. Congrats!

Is there anything else preventing this issue from being closed?

lszomoru commented 2 years ago

@marcusrbrown, I had to revert the change until I fix couple of issues with it. I hope to be able to commit it today.

buondevid commented 2 years ago

Automatic wrapping (subject and/or body) in the Commit Input field on the top-left is still not available, right?

dvnrsn commented 1 year ago

Yes, we could use a configuration option automatically_wrap_git_commit_message at 50 and 72 because some of us write long commits and have to often adjust them and it's a pain to have to readjust every line once editing something toward the top.

Edit: I found rewrap combined with https://github.com/microsoft/vscode/pull/95266 to get me pretty close to what I want. First line has red over 50. All other lines wrap. Maybe there is a way to get perfect with wrapping to rulers but 95% was good enough for me

settings.json

  "[git-commit]": {
    "rewrap.autoWrap.enabled": true,
    "rewrap.wrappingColumn": 72
  }

Note: Might need to command palette: Rewrap Toggle auto wrap to wake it up.

lszomoru commented 10 months ago

Using the complete editor to author commit messages is now part of VS Code. Using the full editor enables configuring editor rulers and wrapping so I will go ahead and close this feature request.

  "[git-commit]": {
    "editor.rulers": [
      72,
      50
    ],
    "editor.wordWrap": "wordWrapColumn",
    "editor.wordWrapColumn": 72
  }