Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. Qt Creator git plugin doesn't properly utilize git hooks

Qt Creator git plugin doesn't properly utilize git hooks

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
gitqtcreatorhooks
2 Posts 2 Posters 1.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sethraymond
    wrote on 19 Dec 2017, 16:25 last edited by sethraymond
    #1

    TL;DR git's prepare-commit-msg hook 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 commit with the -F flag, 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-msg and commit-msg. prepare-commit-msg acts 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-msg is a tool I wrote to check a commit and make sure it conforms to style standards my team has put in place.

    When invoking git commit from the terminal, my hooks work as expected. First, the prepare-commit-msg hook 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-COMMITMSG in the default text editor. When the user is done writing their message, they save and close the file. The commit-msg hook now runs, checking the message in path/to/repo/.git/EDIT-COMMITMSG against 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 path/to/temp/commit/msg to path/to/repo/.git/EDIT-COMMITMSG because the -F flag says to take the commit message from the designated file. It is at this point that my hooks run. prepare-commit-msg prepends 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-msg hook 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-msg is 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.txt can'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.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 19 Dec 2017, 23:05 last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2

      2/2

      19 Dec 2017, 23:05

      • Login

      • Login or register to search.
      2 out of 2
      • First post
        2/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved