Support prepare-commit-msg hooks - #2795
Conversation
Run prepare-commit-msg when GitUp prepares the commit message editor so hook output appears before the user submits the commit. Keep commit-msg validation at commit time using Git's standard COMMIT_EDITMSG file, and preserve user edits if the async prepare hook finishes after typing begins.
|
@DCVortexxx Thank you for the candor in using AI. It gives me the appropriate expectation. I assume you've tested locally? It sounds like a good addition and I will look at the changes soon. This Thursday I'll likely be releasing the 1.5.0 release of GitUp to the stable channel so it won't go in before that. Probably next week is a realistic time for me to start testing out this change. |
|
Hey @lucasderraugh, thanks for getting back to me. Yeah, I tested it locally, through all paths that came to mind :
I also have validated that the implementation is reasonable, according to my knowledge of the codebase of course. Let me know if I can help in any way, and of course, no worries about the timing, |
|
Wonderful, thank you! |
|
@greptile Can you review this PR? |
|
|
Hello @lucasderraugh, just wanted to check if you wanted me to address the Greptile feedbacks? Both
The weak reference is an easy fix. The third one however would require me to get back into the project. Absolutely no rush on that, just wanted to say that I'm still here if needed. |
|
@DCVortexxx Thanks, let me look through them myself tonight and I'll see what I think is still relevant. Thanks for following up. |
lucasderraugh
left a comment
There was a problem hiding this comment.
I'd like to resolve the error being kept around and just let the error show once on the hook failure and not again.
Other than those comments, I think this looks good to go.
|
@lucasderraugh, I've added a dedicated commit to only show the failure, once, when the hook fails. If it looks good to you, I'll squash them and rebase onto master. |
|
All good, I can do that with one button. Thanks for the changes. I have an outstanding continuous build I'm going to move to stable but then we'll kick off a new continuous build soon thereafter. I have some performance improvements I've been meaning to get in as well so we'll try those and this in that next build. |
Disclosure
I AGREE TO THE GITUP CONTRIBUTOR LICENSE AGREEMENT.
Full disclosure, this has been drafted by AI because I haven't played with ObjC for yeeeeeaaaaars, but I believe that it respects the coding standard and contribution rules.
Of course, I'm open to suggestions and will happily update it to make it into master.
I LOVE GitUp and having to rely on another editor just because a project I work on needs this hook on it is a pain 😅
Summary
This adds support for Git's
prepare-commit-msghook when creating commits from GitUp.Git documents
prepare-commit-msgas running after the default commit message is prepared and before the editor starts.To match that lifecycle, GitUp now runs the hook when the commit view prepares the message editor in
viewWillAppear:prepare-commit-msghook should be allowed to finish.It also runs when the user toggles Amend:
prepare-commit-msgwith Git's amend-stylecommitsourceprepare-commit-msgrun, GitUp replaces it with the amend message flow.This also has a side effect on the
commit-msghook, because it used to rely on a app-owned, temporary file for writing the commit message, instead the the$GIT_DIR/COMMIT_EDITMSGfile Git uses.Since
prepare-commit-msgrelies on this file,commit-msgshould read it as well, as the single source of truth for commit message edition.Note
My first implementation ran it when the user actually commits, right before
commit-msg, and it made the code significantly simpler, since we don't need to handle in-flight edit, and "just" update the message in the same waycommit-msgdoes.However, I changed it to be closer to Git's semantics.
Feel free to let me know if you feel like this is a tradeoff worth having.