microsoft / vscode

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

Git commit template should be restored automatically (not only on commit) #75651

Closed dmstern closed 5 years ago

dmstern commented 5 years ago

Background

In #39048, @joaomoreno says about the command git.restoreCommitTemplate:

I don't think it's a command worth putting in the command palette. Seems to be very specific for users who actively modify .gitmessage, doesn't happen often.

This might be true, but there are definitely more actions (than just commit) where it would make sense to read the git commit template, because if you know what you can do with this, this is so damn useful. :)

Problem:

Personally, I use the git commit template to follow our team's git commit message and branch naming conventions, which says that the commit message and the branch you are working on have to be prefixed with the id of the corresponding Jira issue.

So I created a git hook for writing the recently used commit message into the commit template on post-commit and also a hook on post-checkout to write the current branch name (title-cased) into the commit template when I create a new branch. :heavy_check_mark: When I commit something, the git commit template updates and the last commit message stays in the scm message box. :negative_squared_cross_mark: But in order to get the updated content from that template after a git checkout, I have to invoke git.restoreCommitTemplate.

Temporarily I could fix this with a macro extension and mapped the workbench.view.scm keyboard shortcut to my new macro, which does both (git.restoreCommitTemplate and workbench.view.scm). But (a) this works only with this shortcut, not if I click on the scm icon in the activity bar and (b) I think this behavior should be possible without an extension.

Possible solution:

Please invoke git.restoreCommitTemplate every time workbench.view.scm is invoked or on every git.refresh

vscodebot[bot] commented 5 years ago

(Experimental duplicate detection) Thanks for submitting this issue. Please also check if it is already covered by an existing one, like:

joaomoreno commented 5 years ago

Maybe running it on every `git.refresh. isn't too bad, but I'd definitely put that behind a setting. PR?

joaomoreno commented 5 years ago

@dmstern Can you try your flow on today's Insiders? Thanks to another issue's fix, we now support live reloading of the template message:

recording

I believe this would help you and render https://github.com/microsoft/vscode/pull/75767 obsolete. What do you think?

dmstern commented 5 years ago

@joaomoreno Wow, very cool! This is even better than #75767. I'll close my PR.

connor4312 commented 5 years ago

@joaomoreno I'm not sure exactly the extent you mean by 'live reloading'--when I edit my message file, I need to (manually) hit refresh in the git sidebar to have it update the default commit message--it doesn't update automatically when the template it saved. If this is the intended behavior, feel free to mark this issue as verified 🙂

joaomoreno commented 5 years ago

@connor4312 Is the template file you picked inside the workspace folder? If it is outside, we won't have file events hooked up to it.

Easiest way to test is:

  1. Create template file in workspace
  2. Run git config commit.template template

Then, changes in template should eventually be reflected in the commit box.

connor4312 commented 5 years ago

That works :)