diff --git a/app/models/repository/undev_git.rb b/app/models/repository/undev_git.rb index b206fbc..70e0bf5 100644 --- a/app/models/repository/undev_git.rb +++ b/app/models/repository/undev_git.rb @@ -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 @@ -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 diff --git a/init.rb b/init.rb index bd229d5..349a64a 100644 --- a/init.rb +++ b/init.rb @@ -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' diff --git a/test/integration/fire_hooks_on_every_branch_test.rb b/test/integration/fire_hooks_on_every_branch_test.rb index 426a114..c1f1985 100644 --- a/test/integration/fire_hooks_on_every_branch_test.rb +++ b/test/integration/fire_hooks_on_every_branch_test.rb @@ -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!(