Git: how to merge a commit into a branch via an update githook
I’m working on a rather interesting project, attempting to do the following:
Whenever a developer pushes a commit to a remote branch, execute a githook that will lookup its associated QA branch via an issue tracking system, then merge that commit into the QA branch.
What's the equivalent in Git to a read-only component in ClearCase? How to resolve ALL conflicts using HEAD, with any mergetool How do I create a new git branch from an old commit? How to push a new branch non-existing on the remote server without --set-upstream? raco pkg: install subfolder of git repo How to pack/publish a .NET Standard Library to a private VSTS Nuget feed?
It’s important that the commit to the remote branch (mirroring the developer’s local branch) be rejected if there are any conflicts on the QA branch.
The problem I’m running into is that git-merge (and pull, checkout, etc.) must be run in a work tree, which causes the githook to fail.
Is there a (relatively) simple way to merge one branch (or commit) into another via an
update githook? My reasoning being that the remote, while not being a working tree, obviously has all of the data it needs to do this, just not the command (as far as I’ve been able to find).
If there isn’t a straightforward command, my next thought is to create a temporary clone of the remote in which I can perform the merge operation:
(psuedocode) mkdir $GIT_DIR/tempRepo cd $GIT_DIR/tempRepo git clone -b $QA_BRANCH --local $PARENT_DIR $CURRENT_DIR git merge $WHATEVER #cleanup
If any part of this fails, I reject the
update (hopefully with some useful info to the developer so he/she can fix it). I’ve played with this solution a bit and while it appears to work fine via my script, it fails when running on a real remote (I don’t know why yet, but while typing this, this answer popped up that may help – getting "fatal: not a git repository: '.'" when using post-update hook to execute 'git pull' on another repo)
I’d love any insight from the git gurus around here, I’m still fairly new to the plumbing that underpins this whole system, so if I’m on the right (or wrong) track, or if there are some magical commands or gotchas I should know about, I’d appreciate it.
Thanks in advance!