SQL Source Control Git Hook Support
Sql Source Control can be made better by adding support for git hooks in the Sql Management Studio Source Control interface.
Example: Create a pre-commit hook to stop outgoing commits if tsqlt tests do not pass.
Expected outcome: A commit that fails the pre-commit hook should not be created. This is the behavior of the git command line.
Current outcome: Sql Source Control does not respect the git hook and bypasses it allowing the commit to be made.
SQL Source Control 7 has now been released. In this version, SQL Source Control now uses the Git command line for all its Git interactions, which means it will support any Git hooks that have been configured.
You will need to ensure that you have Git.exe available in your system path – the easiest way to do this if you don’t already have Git installed is to download Git for windows (https://git-scm.com/download/win)
-
Anonymous
commented
Yes I would like to see that user is required a message before we commit.
-
Sam Blowes
commented
Hello and thank you for implementing this!
However the commit message passed to the commit-msg hook is not the message that is defined by the user, instead it is a message generated by the tool.
How can this be fixed?
-
Aaron Templeton
commented
Please be aware, I consider this to be fallout from git not honoring commit hooks in general. Which is referenced by the following support request:
https://redgate.uservoice.com/forums/39019-sql-source-control/suggestions/33730249-sql-source-control-git-hook-supportIf the hooks were honored, you would create a simple git hook that required a comment. That requirement would then be honored by all systems (command line, Visual Studio, etc), not just SQL Source Control. At present, SQL Source Control is still using the gitlib2 library which does not honor hooks. The command line does honor hooks. Visual Studio converted away from gitlib2 as of VS 2017 and thus now honors the hooks.
-
Aaron Templeton
commented
This appears to be a failing of the libgit2 API which Redgate is using. It does not run any of the hooks, commit-msg in this case. Microsoft suffered the same failing with Visual Studio until they converted over to directly running the git.exe shell as of VS 2017. I would ask that you take a similar initiative. For now, we are catching the failings in a bare repository pre-receive hook which then forces the user to repair their local repository through either a "git commit --amend" or else an interactive rebase. This gets especially messy if they have already done any branch merging. Please see for reference: https://visualstudio.uservoice.com/forums/121579-visual-studio-ide/suggestions/4321705-enable-client-side-hooks-when-committing-code-to-a
-
Aaron Templeton
commented
Upon further research this appears to be a failing of the libgit2 API which you are using. Microsoft suffered the same failing with Visual Studio until they converted over to directly running the git.exe shell as of VS 2017. I would ask that you take a similar initiative. For now, we are catching the failings in a bare repository pre-receive hook which then forces the user to repair their local repository through either a "git commit --amend" or else an interactive rebase. This gets especially messy if they have already done any branch merging. Please see for reference: https://visualstudio.uservoice.com/forums/121579-visual-studio-ide/suggestions/4321705-enable-client-side-hooks-when-committing-code-to-a
-
Aaron Templeton
commented
I could almost swear that SQL Source Control used to honor the hook, or at least ran it even if it didn't honor the return code to abort. Now I'm finding it doesn't run the hook at all. I altered my hook to create a file, which is never created from Redgate, and had it append a constant to the message, which never gets appended, before exiting with a zero return code. So it isn't that SQL Source Control is not honoring the hook, it simply isn't even running that code any longer. Or perhaps ever, but I'm 99.99% sure it used to at least run the hook allowing content to be appended to the message. So it appears to have recently went from "broken" to "really broken".
-
Sam Blowes
commented
This is very important for audit purposes.
Often a user should reference a ticket for each change.
-
Roman
commented
I support this. It´s really annoying to get ´no comments´ commit in our system.
-
schmidlop
commented
Git requires a commit message by default however SQL Source Control circumvents this setting and commits without a message. There are a few other submissions attempting to get this fixed which have been declined. Seems you are missing the point.
In the case "Empty commit message for git is invalid" the very article you've linked points out that it takes special command line flag to commit without a message. SQL source control commits without a message and provides no mechanism to prevent this. There is no configuration for git that will do this because the default git behavior is already requires a commit message! Unfortunately SQL source control is subverting this. Please stop subverting the default git commit behavior or provide a setting to enforce a commit message...