Consider next pseudo-code thats create a required git log:
git checkout master
git checkout -b 123-test-branch-1
git commit -m "#123 b1 c1"
git commit -m "#123 b1 c2"
git push
git checkout master
git checkout -b 456-test-branch-2
git commit -m "#456 b2 c1"
git commit -m "#456 b2 c2"
git push
git checkout 123-test-branch-1
git merge 456-test-branch-2
git commit -m "#123 b1 c3"
git push
In a real-world my update
hook in remote git repository validates branch name and commit message formats. Branch name and commit message must contain issue number, for example, in 123-test-branch-1
and #123 b1 c1
the issue number is 123
. When branch is pushed, hook extract issue number from branch and commit message and compare it. If they are not equal, hook exits with error.
This works great, when I push branch that has only "own" commits. But, git log example above, pushed branch 123-test-branch-1
has commits from merged branch 456-test-branch-2
so hook try to compare all commits from both branches only with pushed branch 123-test-branch-1
and exits with error because commits from 456-test-branch-2
has issue number 456
, when 123
is expected.
To receive commits, I use git log --pretty=%s ${oldRef}..${newRef}
, where oldRef
and newRef
is "update" hook arguments.
So, my question is how to solve this problem. Somehow group commits per branch, or filter commits from branch that pushed now (but if 456-test-branch-2
is local branch and never pushed and never validated, hook may skip invalid commits), or something else.