git - Get source branch name in commit-msg hook of merge commit -


in commit-msg hook merge commit, how can branch name of immediate source branch merge? can target branch like

git rev-parse --abbrev-ref head 

but head , head^ both refer target branch. there way programmatically determine source? i'm using bash script hook.

the default merge commit message contains text:

merge branch 'source-branch' target-branch

so commit-msg hook grab name right out of message, there's no guarantee user hasn't edited it. if there's more foolproof method, prefer it.

edit: ah, unfortunately didn't realize commit-msg doesn't run on merge commits! i'll have find different way want anyway.

this give commit being merged:

git rev-parse merge_head 

i not think there way find branch name other guessing command like:

git for-each-ref | grep ^$(git rev-parse merge_head) 

(which finds branches pointing commit merging)

note commit being merged not have to branch, 1 can merge commit directly git merge deadbeef.

in case of octopus merge, there more 1 commit being merged @ same time, , merge_head not present.

if extract merge message, using .git/merge_msg safer .git/commit_editmsg, since less hand-edited.

the message generated git merge, hence has access branch name git merge's arguments, not seem stored on disk.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -