Skip to content

Commit

Permalink
Fix push not allowed to protected branch if
Browse files Browse the repository at this point in the history
commit starts with 7 zeros.
  • Loading branch information
cirosantilli committed Nov 3, 2014
1 parent 1b14038 commit d4d2701
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions lib/gitlab/git.rb
@@ -0,0 +1,5 @@
module Gitlab
module Git
DELETED_SHA = '0' * 40
end
end
4 changes: 2 additions & 2 deletions lib/gitlab/git_access.rb
Expand Up @@ -67,7 +67,7 @@ def change_allowed?(user, project, change)
if forced_push?(project, oldrev, newrev)
:force_push_code_to_protected_branches
# and we dont allow remove of protected branch
elsif newrev =~ /0000000/
elsif newrev == Gitlab::Git::BLANK_SHA
:remove_protected_branches
else
:push_code_to_protected_branches
Expand All @@ -85,7 +85,7 @@ def change_allowed?(user, project, change)
def forced_push?(project, oldrev, newrev)
return false if project.empty_repo?

if oldrev !~ /00000000/ && newrev !~ /00000000/
if oldrev != Gitlab::Git::BLANK_SHA && newrev != Gitlab::Git::BLANK_SHA
missed_refs = IO.popen(%W(git --git-dir=#{project.repository.path_to_repo} rev-list #{oldrev} ^#{newrev})).read
missed_refs.split("\n").size > 0
else
Expand Down
7 changes: 4 additions & 3 deletions spec/lib/gitlab/git_access_spec.rb
Expand Up @@ -55,12 +55,13 @@ def protect_feature_branch

def changes
{
push_new_branch: '000000000 570e7b2ab refs/heads/wow',
push_new_branch: "#{Gitlab::Git::BLANK_SHA} 570e7b2ab refs/heads/wow",
push_master: '6f6d7e7ed 570e7b2ab refs/heads/master',
push_protected_branch: '6f6d7e7ed 570e7b2ab refs/heads/feature',
push_remove_protected_branch: '570e7b2ab 000000000 refs/heads/feature',
push_remove_protected_branch: "570e7b2ab #{Gitlab::Git::BLANK_SHA} "\
'refs/heads/feature',
push_tag: '6f6d7e7ed 570e7b2ab refs/tags/v1.0.0',
push_new_tag: '000000000 570e7b2ab refs/tags/v7.8.9',
push_new_tag: "#{Gitlab::Git::BLANK_SHA} 570e7b2ab refs/tags/v7.8.9",
push_all: ['6f6d7e7ed 570e7b2ab refs/heads/master', '6f6d7e7ed 570e7b2ab refs/heads/feature']
}
end
Expand Down

0 comments on commit d4d2701

Please sign in to comment.