Skip to content

Git hooks check old commits when creating branch from another branch

We're having an issue where when creating a branch from another branch the member_check git hook fails. This is an issue for us, as we have many imported projects which contain existing commits from people who never had an account in GitLab.

Create a new project, with member_check git_hook disabled. Clone the empty project, and do the following:

git config --local user.email "john.doe@example.com"
echo ${RANDOM} > README; git add README; git commit -m"Testing" README
git push
git checkout -b new-branch-1
echo ${RANDOM} > README; git commit -m"Testing" README
git push -u origin new-branch-1

Now enable the member check and continue as follows:

git config --local user.email "<Your valid member e-mail>"
git checkout master
git checkout -b new-branch-2
git push -u origin new-branch-2
git checkout new-branch-1
git checkout -b new-branch-3
git push -u origin new-branch-3

With the branch created from new-branch-1 instead of master, the commit hook denies the push. Even though there are no new commits and it should be no different than with new-branch-2 which was created from master.

I suspect (I'm not a developer) it's going wrong in lib/gitlab/git_access.rb on line 191 where oldrev is actively set to the default branch:

oldrev = project.default_branch if Gitlab::Git.blank_ref?(oldrev)

Probably either oldrev should be set to the branch the new branch is created from or the rev-list should be retrieved as in:

git rev-list newrev --not --all

See this StackOverflow post: http://stackoverflow.com/a/22547375/114983

Kind regards, Bartosz