From 6173d0a92f4b8e472d5d71e3518ae5460257d39e Mon Sep 17 00:00:00 2001 From: Andrey Kumanyaev Date: Tue, 15 Oct 2013 16:59:48 +0400 Subject: [PATCH] Show branches list (which branches contains commit) on commit page --- app/assets/javascripts/main.js.coffee | 4 ++++ app/contexts/commit_load_context.rb | 1 + app/controllers/projects/commit_controller.rb | 1 + app/helpers/commits_helper.rb | 11 +++++++++++ app/views/projects/commit/_commit_box.html.haml | 12 ++++++++++++ 5 files changed, 29 insertions(+), 0 deletions(-) diff --git a/app/assets/javascripts/main.js.coffee b/app/assets/javascripts/main.js.coffee index 011244a..ccd5ad4 100644 --- a/app/assets/javascripts/main.js.coffee +++ b/app/assets/javascripts/main.js.coffee @@ -123,6 +123,10 @@ $ -> $(@).next('table').show() $(@).remove() + $(".content").on "click", ".js-details-expand", -> + $(@).next('.js-details-contain').removeClass("hide") + $(@).remove() + (($) -> _chosen = $.fn.chosen $.fn.extend chosen: (options) -> diff --git a/app/contexts/commit_load_context.rb b/app/contexts/commit_load_context.rb index 2930c5b..0c68497 100644 --- a/app/contexts/commit_load_context.rb +++ b/app/contexts/commit_load_context.rb @@ -18,6 +18,7 @@ class CommitLoadContext < BaseContext result[:note] = project.build_commit_note(commit) result[:line_notes] = line_notes result[:notes_count] = project.notes.for_commit_id(commit.id).count + result[:branches] = project.repository.branch_names_contains(commit.id) begin result[:suppress_diff] = true if commit.diff_suppress? && !params[:force_show_diff] diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb index bdc501d..242aa41 100644 --- a/app/controllers/projects/commit_controller.rb +++ b/app/controllers/projects/commit_controller.rb @@ -22,6 +22,7 @@ class Projects::CommitController < Projects::ApplicationController @note = result[:note] @line_notes = result[:line_notes] + @branches = result[:branches] @notes_count = result[:notes_count] @target_type = :commit @target_id = @commit.id diff --git a/app/helpers/commits_helper.rb b/app/helpers/commits_helper.rb index 7e24cbd..c340eb3 100644 --- a/app/helpers/commits_helper.rb +++ b/app/helpers/commits_helper.rb @@ -94,6 +94,17 @@ module CommitsHelper crumbs.html_safe end + # Return Project default branch, if it present in array + # Else - first branch in array (mb last actual branch) + def commit_default_branch(project, branches) + branches.include?(project.default_branch) ? branches.delete(project.default_branch) : branches.pop + end + + # Returns the sorted alphabetically links to branches, separated by a comma + def commit_branches_links(project, branches) + branches.sort.map { |branch| link_to(branch, project_tree_path(project, branch)) }.join(", ").html_safe + end + protected # Private: Returns a link to a person. If the person has a matching user and diff --git a/app/views/projects/commit/_commit_box.html.haml b/app/views/projects/commit/_commit_box.html.haml index 1f49345..b45847f 100644 --- a/app/views/projects/commit/_commit_box.html.haml +++ b/app/views/projects/commit/_commit_box.html.haml @@ -39,6 +39,18 @@ - @commit.parents.each do |parent| = link_to parent.id[0...10], project_commit_path(@project, parent) +.commit-info-row + %span.cgray + Exists in + %span + - branch = commit_default_branch(@project, @branches) + = link_to(branch, project_tree_path(@project, branch)) + - if @branches.any? + and in + = link_to("#{pluralize(@branches.count, "other branch")}", "#", class: "js-details-expand") + %span.js-details-contain.hide + = commit_branches_links(@project, @branches) + .commit-box %h3.commit-title = gfm escape_once(@commit.title) -- libgit2 0.21.2