Skip to content

Commit

Permalink
fix bug when hooks aplied twice
Browse files Browse the repository at this point in the history
  • Loading branch information
nodecarter committed Sep 2, 2013
1 parent 14bb89e commit 62da6a4
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
13 changes: 6 additions & 7 deletions app/models/repository/undev_git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,7 @@ def fetch_changesets
save_revisions(prev_heads, repo_heads)

# don't apply hooks for already prepared changesets in first fetch
exclude_branches = {}
if prev_branches.empty?
repo_branches.each { |b| exclude_branches[b.to_s] = b.scmid }
else
exclude_branches = prev_branches
end
apply_hooks_for_merged_commits(exclude_branches, repo_branches)
apply_hooks_for_merged_commits(prev_branches, repo_branches) unless prev_branches.empty?

h1 = extra_info || {}
h = h1.dup
Expand Down Expand Up @@ -374,6 +368,11 @@ def apply_hooks_for_merged_commits(prev_branches, repo_branches)
scmids = revisions.slice(offset, limit).map { |r| r.scmid }
cs = changesets.where('scmid IN (?)', scmids).order('committed_on DESC')
cs.each do |changeset|

# branches added to changeset at the first save
# for all these branches hooks was already applied
next if changeset.branches.include?(hook_branch)

apply_hooks_for_branch(changeset, hook_branch)
end
offset += limit
Expand Down
2 changes: 1 addition & 1 deletion init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
description 'Git repository with remote repositories and hooks support'
author 'Denis Diachkov, Vladimir Kiselev, Danil Tashkinov'
author_url 'https://github.com/Undev'
version '0.2.4'
version '0.2.5'
url 'https://github.com/Undev/redmine_undev_git'

requires_redmine :version_or_higher => '2.1'
Expand Down
16 changes: 16 additions & 0 deletions test/integration/fire_hooks_on_every_branch_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,22 @@ def test_hooks_priority_3
assert_equal [], @hook_ids4
end

def test_hooks_for_merged_commits
hook_feature = GlobalHook.create!(
:keywords => 'hook6, hook7', :branches => 'feature', :new_done_ratio => '11%')
hook_staging = GlobalHook.create!(
:keywords => 'hook6, hook7', :branches => 'staging', :new_done_ratio => '12%')

@repo.reload

fetch_changesets_by_step

assert_equal [], @hook_ids1
assert_equal [hook_feature.id, hook_staging.id], @hook_ids2
assert_equal [], @hook_ids3
assert_equal [], @hook_ids4
end

def create_global_hooks
[
GlobalHook.create!(
Expand Down

0 comments on commit 62da6a4

Please sign in to comment.