yysun / git-tools

This extension provides a git changes tool window, a graphical git history viewer and menus to launch Git Bash, Git Extenstions and TortoiseGit.
http://yysun.github.com/git-tools
MIT License
78 stars 27 forks source link

Add prepare-commit-msg hook support #15

Closed a-bastin closed 7 years ago

a-bastin commented 7 years ago

I use this plugin to add git feature to VS 2015 entreprise, such as commit-msg hook wich validate my commit message and display an error if my rule is not respected. Is it possible to have the same behavior with the prepare-commit-msg ? For example with this hook :

#!/bin/sh
firstLine=`head -2 $1 | tail -1`
if [[ $firstLine == \#* ]]; then # Testing that the file starts with a comment, not yet a real commit
  echo '<type>(<component>): <subject>' > .prepare-commit-msg-temp
  echo '' >> .prepare-commit-msg-temp
  echo '<body>' >> .prepare-commit-msg-temp
  echo '' >> .prepare-commit-msg-temp
  echo '# types: feat, fix, docs, style, refactor, test, chore(mantain)' >> .prepare-commit-msg-temp
  { cat .prepare-commit-msg-temp; cat $1; } > .prepare-commit-msg-temp2
  cat .prepare-commit-msg-temp2 > $1
  rm .prepare-commit-msg-temp .prepare-commit-msg-temp2
fi

the comments text area in the commit tab will be filled with :

<type>(<component>): <subject>

<body>

# types: feat, fix, docs, style, refactor, test, chore(mantain)
yysun commented 7 years ago

What you can do is to save your template to a file, eg .gitmessage.txt. Then set git config commit.template to the file as described here: https://git-scm.com/book/en/v2/Customizing-Git-Git-Configuration

git config --add commit.template .gitmessage.txt

Next release of this extension will load commit template.from git config into the comment text box.

a-bastin commented 7 years ago

Thanks ! I'm looking forward for the next release ;)

a-bastin commented 7 years ago

Working with the 2.0.0 version, thank you !!