From 8adf6ba8f5bf9086ec3f9bb54ad801deb4d41924 Mon Sep 17 00:00:00 2001 From: "Florent (HP)" Date: Sun, 9 Aug 2015 20:31:50 +0200 Subject: [PATCH] Add merged label on branches page --- CHANGELOG | 1 + app/models/repository.rb | 11 ++++++++++ app/views/projects/branches/_branch.html.haml | 5 +++++ spec/models/repository_spec.rb | 20 +++++++++++++++++++ 4 files changed, 37 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index e14255ee9b2..16ed0470f8e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -55,6 +55,7 @@ v 7.14.0 (unreleased) - Fix bug causing error when the target branch of a symbolic ref was deleted - Include branch/tag name in archive file and directory name - Add dropzone upload progress + - Add a label for merged branches on branches page (Florent Baldino) v 7.13.3 - Fix bug causing Bitbucket importer to crash when OAuth application had been removed. diff --git a/app/models/repository.rb b/app/models/repository.rb index 0a62980f93a..3bba3ca888a 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -364,6 +364,17 @@ class Repository @root_ref ||= raw_repository.root_ref end + def merged_to_root_ref?(branch_name) + branch_commit = commit(branch_name) + root_ref_commit = commit(root_ref) + + if branch_commit + rugged.merge_base(root_ref_commit.id, branch_commit.id) == branch_commit.id + else + nil + end + end + def search_files(query, ref) offset = 2 args = %W(git grep -i -n --before-context #{offset} --after-context #{offset} #{query} #{ref || root_ref}) diff --git a/app/views/projects/branches/_branch.html.haml b/app/views/projects/branches/_branch.html.haml index 43412624da6..a693c4b282f 100644 --- a/app/views/projects/branches/_branch.html.haml +++ b/app/views/projects/branches/_branch.html.haml @@ -5,6 +5,11 @@ %strong.str-truncated= branch.name - if branch.name == @repository.root_ref %span.label.label-info default + - elsif @repository.merged_to_root_ref? branch.name + %span.label.label-primary.has_tooltip(title="Merged into #{@repository.root_ref}") + %i.fa.fa-check + merged + - if @project.protected_branch? branch.name %span.label.label-success %i.fa.fa-lock diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb index 0927cde61a6..8e2849691ff 100644 --- a/spec/models/repository_spec.rb +++ b/spec/models/repository_spec.rb @@ -34,6 +34,26 @@ describe Repository do end end + describe :merged_to_root_ref? do + context 'merged branch' do + subject { repository.merged_to_root_ref?('improve/awesome') } + + it { is_expected.to be_truthy } + end + + context 'non merged branch' do + subject { repository.merged_to_root_ref?('fix') } + + it { is_expected.to be_falsey } + end + + context 'non existent branch' do + subject { repository.merged_to_root_ref?('non_existent_branch') } + + it { is_expected.to be_nil } + end + end + describe "search_files" do let(:results) { repository.search_files('feature', 'master') } subject { results }