Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git: Support prepare-commit-msg hook #94274

Closed
Khady opened this issue Apr 2, 2020 · 4 comments
Closed

Git: Support prepare-commit-msg hook #94274

Khady opened this issue Apr 2, 2020 · 4 comments
Labels
feature-request Request for new features or functionality git GIT issues help wanted Issues identified as good community contribution opportunities

Comments

@Khady
Copy link

Khady commented Apr 2, 2020

  • VSCode Version: 1.43.2
  • OS Version: ubuntu 19.10

In vscode, during a git commit, the prepare-commit-msg hook of git runs only after the message is already inputed by the user. It defeats the fact that this hook must prepare the message for the user.

The prepare-commit-msg hook is run before the commit message editor is fired up but after the default message is created.
https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks (emphasis is mine)

It means that the user can't benefit from the prepared message. For example, I have a hook which adds 10 lines of comments. Those comments contain some info that is helping me to write the final message. Ideally the prepare-commit-msg hook should run first, then the content created by the hook must go into the commit message input box, then the user can edit this text.

Apparently vscode is trying to commit by using an equivalent of git commit -m "the message", at least that is what I understand from the 2=message in step 12.

An additional note, it seems that if the message inputted by the user in vscode during a Git: Commit is # foo (so starting with a #), the hook doesn't run. That's... surprising?

Steps to Reproduce:

  1. in a git repo create .git/hook/prepare-commit-msg with this content
echo "1=$1 2=$2 3=$3" > "$1"
date >> "$1"
cp "$1" /tmp/investigate-prepare-commit-msg
  1. chmod +x .git/hook/prepare-commit-msg
  2. run git commit --allow-empty and do not close the editor yet
  3. check that the editor contains a message like
# some comment
1=.git/COMMIT_EDITMSG 2= 3=
Thu Apr  2 09:49:55 GMT 2020
  1. check that /tmp/investigate-prepare-commit-msg contains the same message
  2. close the editor and run rm /tmp/investigate-prepare-commit-msg
  3. echo "creating a diff" > some_file && git add some_file && code .
  4. in vscode, execute Git: Commit and do not input a message yet
  5. check that the input box for the commit message is empty
  6. check that /tmp/investigate-prepare-commit-msg does not exist
  7. input a commit message and press enter
  8. check that /tmp/investigate-prepare-commit-msg now exists and contains
# some comment
1=.git/COMMIT_EDITMSG 2=message 3=
Thu 02 Apr 2020 10:00:31 AM GMT

note the 2=message part
13. check that the commit contains the same thing as /tmp/investigate-prepare-commit-msg

Does this issue occur when all extensions are disabled?: Yes

@vscodebot
Copy link

vscodebot bot commented Apr 2, 2020

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

@joaomoreno joaomoreno changed the title Git: commit runs prepare-commit-msg hook too late and doesn't show the prepared message Git: Support prepare-commit-msg hook Apr 2, 2020
@joaomoreno joaomoreno added feature-request Request for new features or functionality git GIT issues help wanted Issues identified as good community contribution opportunities labels Apr 2, 2020
@joaomoreno joaomoreno added this to the Backlog Candidates milestone Apr 2, 2020
@vscodebot
Copy link

vscodebot bot commented Apr 2, 2020

This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

@joaomoreno joaomoreno removed their assignment Apr 2, 2020
@Khady
Copy link
Author

Khady commented May 23, 2020

Will be fixed by #95266

@Khady Khady closed this as completed May 23, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Jul 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality git GIT issues help wanted Issues identified as good community contribution opportunities
Projects
None yet
Development

No branches or pull requests

3 participants
@joaomoreno @Khady and others