Commit d69d4381 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'fix/git-annex-githooks' into 'master'

Disable githoooks for git annex commits

Fixes https://gitlab.com/gitlab-org/gitlab-ee/issues/40

<s>This fix checks if the commit `SHA` is also in one of the synced `git-annex` branches, which means that it should safely skip git hooks. </s> This may not work with multiple commits to the synced branch

These `git-annex` commits also consistently have a message starting with git-annex blah... Using this, as probability of false positives is very low.

See merge request !272
parents a88a6d4b ddb8d2b8
......@@ -41,6 +41,7 @@ v 8.6.0 (unreleased)
- Allow SSL verification to be configurable when importing GitHub projects
- Move group activity to separate page
- Continue parameters are checked to ensure redirection goes to the same instance
- Disable git-hooks for git annex commits
v 8.5.6
- Obtain a lease before querying LDAP
......
......@@ -213,6 +213,8 @@ module Gitlab
end
commits.each do |commit|
next if commit_from_annex_sync?(commit.safe_message)
if status_object = check_commit(commit, git_hook)
return status_object
end
......@@ -364,5 +366,12 @@ module Gitlab
true
end
def commit_from_annex_sync?(commit_message)
return false unless Gitlab.config.gitlab_shell.git_annex_enabled
# Commit message starting with <git-annex in > so avoid git hooks on this
commit_message.start_with?('git-annex in')
end
end
end
......@@ -9,6 +9,7 @@ describe Gitlab::GitAccess, lib: true do
["6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/synced/git-annex",
"6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/synced/named-branch"]
end
let(:git_annex_master_changes) { "6f6d7e7ed97bb5f0054f2b1df789b39ca89b6ff9 570e7b2abdd848b95f2f578043fc23bd6f6fd24d refs/heads/master" }
describe 'can_push_to_branch?' do
describe 'push to none protected branch' do
......@@ -323,6 +324,15 @@ describe Gitlab::GitAccess, lib: true do
it { expect(access.push_access_check(git_annex_changes)).to be_allowed }
end
describe 'git annex enabled, push to master branch' do
before do
allow(Gitlab.config.gitlab_shell).to receive(:git_annex_enabled).and_return(true)
allow_any_instance_of(Commit).to receive(:safe_message) { 'git-annex in me@host:~/repo' }
end
it { expect(access.push_access_check(git_annex_master_changes)).to be_allowed }
end
describe 'git annex disabled' do
before { allow(Gitlab.config.gitlab_shell).to receive(:git_annex_enabled).and_return(false) }
......@@ -330,7 +340,7 @@ describe Gitlab::GitAccess, lib: true do
end
end
describe 'check commit author email' do
describe 'check max file size' do
before do
allow_any_instance_of(Gitlab::Git::Blob).to receive(:size).and_return(5.megabytes.to_i)
project.git_hook.update(max_file_size: 2)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment