Qt Creator git plugin doesn't properly utilize git hooks
prepare-commit-msghook doesn't work as expected in Qt Creator for two reasons. First, the GUI always assumes we want to start with a blank commit message. Second, Qt Creator uses a temporary message file and calls
git commitwith the
-Fflag, meaning no hooks are run until the commit message is already complete. Is this desired behavior?
I have two git hooks in my repository,
prepare-commit-msgacts as a way to template a commit by inserting the branch name and some other items into the commit message before the user even sees it.
commit-msgis a tool I wrote to check a commit and make sure it conforms to style standards my team has put in place.
git commitfrom the terminal, my hooks work as expected. First, the
prepare-commit-msghook is run, templating my commit message and writing it to the default commit message file,
path/to/repo/.git/EDIT-COMMITMSG. Then, git opens the now templated
path/to/repo/.git/EDIT-COMMITMSGin the default text editor. When the user is done writing their message, they save and close the file. The
commit-msghook now runs, checking the message in
path/to/repo/.git/EDIT-COMMITMSGagainst it's rules. If successful, all is good and git logs the commit. Otherwise, it aborts.
However, when using Qt Creator, I found that my hooks do not behave the same way. What I found is that Qt Creator doesn't use the typical git commit message (
path/to/repo/.git/EDIT-COMMITMSG). Instead, what Qt Creator appears to do is pop up its git commit GUI with an empty string buffer (the Description box). When the user clicks the "Commit" button in the GUI, the data in the string buffer (the commit message) is saved to a temporary file location. Then, Qt Creator calls
git commit -F path/to/temp/commit/msg. git, in the background, copies the contents of
-Fflag says to take the commit message from the designated file. It is at this point that my hooks run.
prepare-commit-msgprepends my template to the already populated
path/to/repo/.git/EDIT-COMMITMSG. We skip opening the file with our text editor, and next the
commit-msghook is run. My default template does not pass the check, and the commit is aborted.
Is this the desired behavior? The takeaway here is that
prepare-commit-msgis pretty much useless in Qt Creator if you want to edit your commit message before the user touches it. I'm getting around it by using git's template feature, but my
template.txtcan't populate its contents on-the-fly like a shell or Python script can. I could handle styling the commit message after the user has submitted the message, but I don't want to silently edit their message and confuse them down the road.
Hi and welcome to devnet,
I’d say it’s likely not. I’d recommend bringing this excellent question to the Qt Creator mailing list. You’ll find there Qt Creator’s developers/maintainers. This forum is more user oriented.