diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb index 34bd682bd9094d724c6f195a65cc4ab917187c0a..66c67b661dbe92c9d19f769c1d01bc07b99baeae 100644 --- a/app/controllers/projects/commit_controller.rb +++ b/app/controllers/projects/commit_controller.rb @@ -12,13 +12,7 @@ class Projects::CommitController < Projects::ApplicationController return git_not_found! unless @commit @line_notes = project.notes.for_commit_id(commit.id).inline - - @branches = begin - project.repository.branch_names_contains(commit.id) - rescue Grit::Git::GitTimeout - [] - end - + @branches = project.repository.branch_names_contains(commit.id) @diffs = @commit.diffs @note = project.build_commit_note(commit) @notes_count = project.notes.for_commit_id(commit.id).count diff --git a/app/models/repository.rb b/app/models/repository.rb index ea87ea88fdcff8962e1e1f2e87ac53d04f0e8de8..4108c4ee96ebc03be4e4fa3f053a92d82f79a52c 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -284,4 +284,21 @@ class Repository blob_at(commit.parent_id, diff.old_path) end end + + def branch_names_contains(sha) + args = %W(git branch --contains #{sha}) + names = Gitlab::Popen.popen(args, path_to_repo).first + + if names.respond_to?(:split) + names = names.split("\n").map(&:strip) + + names.each do |name| + name.slice! '* ' + end + + names + else + [] + end + end end diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..6c3e221f34372200cf8af9171d8b38578f61be10 --- /dev/null +++ b/spec/models/repository_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe Repository do + include RepoHelpers + + let(:repository) { create(:project).repository } + + describe :branch_names_contains do + subject { repository.branch_names_contains(sample_commit.id) } + + it { should include('master') } + it { should_not include('feature') } + it { should_not include('fix') } + end + + describe :last_commit_for_path do + subject { repository.last_commit_for_path(sample_commit.id, '.gitignore').id } + + it { should eq('c1acaa58bbcbc3eafe538cb8274ba387047b69f8') } + end +end