I am writing a custom merge driver that needs to know the names of the branches it merges. I managed to get the name of the branch that merges at (destination) with git symbolic-ref HEAD and the name of the branch that merges at (source) from the GITHEAD_<SHA> environment variable.
# retrieve merged branch name from an env var GITHEAD_<sha>=<branchName> # we cannot use a sym ref of MERGE_HEAD, as it doesn't yet exist gitHead=$(env | grep GITHEAD) # eg GITHEAD_<sha>=release/1.43 # cut out everything up to the last "=" sign source="${gitHead##*=}" # retrieve base branch name from a sym ref of HEAD branch=$(git symbolic-ref HEAD) # eg refs/heads/master # cut out "refs/heads" destination="${branch#refs/heads/}" echo "Merging from $source into $destination"
Is this the right way to do this? In particular, getting the original name from an environment variable seems like a screen. Please note that MERGE_HEAD is currently missing, so I cannot use the same approach as with HEAD.
source share