Reputation: 315
We have gitlab set up on our own server. I need a server side hook that will read each commit message and add the branch name on which the commit is made at the beginning of the message. Is it possible to modify the commit message during push? I read that it is possible to modify commit messages on the client side link but can it be done on server side.
Any help.
Upvotes: 0
Views: 1360
Reputation: 38734
It is a veeeery bad idea to modify commits in any way on push. The message is part of the commit ID and thus you will essential make the commit a different commit with a different SHA if you would do such a thing.
Furthermore, a commit does not belong to any branch. A commit can be part of the history of 0, 1 or any other amount of branches. You can only determine to which branches (plural) a commit belongs at the time you are looking. This can change any time basically.
On client side there are hooks that pre-format the commit message or post-process the commit message before / after the editor is invoked when a commit is created, but at this point the commit is not yet present and thus you influence how it will be created, but do not change it which really would be a terrible idea due to several reasons.
What you could do in a server side hook is you could add notes to the commits where you mention the branches to which the commit belongs at push time in a post-receive hook. Notes attached to commits do not change the commits themselves.
Upvotes: 5