Commit 9cd8f7b0 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

New Feature: Git Blame for file

parent 2e54ac17
...@@ -268,6 +268,13 @@ img.avatar { ...@@ -268,6 +268,13 @@ img.avatar {
-webkit-border-radius: 4px; -webkit-border-radius: 4px;
-moz-border-radius: 4px; -moz-border-radius: 4px;
border-radius: 4px; border-radius: 4px;
&.s16 {
width:16px;
}
&.s24 {
width:24px;
}
} }
img.lil_av { img.lil_av {
......
...@@ -53,6 +53,11 @@ ...@@ -53,6 +53,11 @@
padding: 9px 10px; padding: 9px 10px;
height:18px; height:18px;
.options {
float:right;
margin-top: -5px;
}
.file_name { .file_name {
color:$style_color; color:$style_color;
font-size:14px; font-size:14px;
...@@ -220,3 +225,27 @@ ...@@ -220,3 +225,27 @@
margin:0; margin:0;
} }
} }
.blame_file {
.view_file_content {
tr {
border-bottom: 1px solid #eee;
}
td {
padding:5px;
}
.author,
.commit {
background:#f5f5f5;
vertical-align:top;
}
.lines {
pre {
padding:0;
margin:0;
background:none;
border:none;
}
}
}
}
...@@ -8,7 +8,7 @@ class RefsController < ApplicationController ...@@ -8,7 +8,7 @@ class RefsController < ApplicationController
before_filter :require_non_empty_project before_filter :require_non_empty_project
before_filter :ref before_filter :ref
before_filter :define_tree_vars, :only => [:tree, :blob] before_filter :define_tree_vars, :only => [:tree, :blob, :blame]
before_filter :render_full_content before_filter :render_full_content
layout "project" layout "project"
...@@ -62,6 +62,10 @@ class RefsController < ApplicationController ...@@ -62,6 +62,10 @@ class RefsController < ApplicationController
return render_404 return render_404
end end
def blame
@blame = Grit::Blob.blame(@repo, @commit.id, params[:path])
end
protected protected
def define_tree_vars def define_tree_vars
......
%ul.nav.nav-tabs
%li
= form_tag switch_project_refs_path(@project), :method => :get, :class => "project-refs-form", :remote => true do
= select_tag "ref", grouped_options_refs, :onchange => "$(this.form).trigger('submit');", :class => "project-refs-select"
= hidden_field_tag :destination, "tree"
= hidden_field_tag :path, params[:path]
%li{:class => "#{'active' if (controller.controller_name == "refs") }"}
= link_to tree_project_ref_path(@project, @ref) do
Code
:css
.view_file .view_file
.view_file_header .view_file_header
%i.icon-file %i.icon-file
%span.file_name %span.file_name
= name = name
%small #{file.mode} %small #{file.mode}
%span.right %span.options
= link_to "raw", blob_project_ref_path(@project, @ref, :path => params[:path]), :class => "right", :target => "_blank" = link_to "raw", blob_project_ref_path(@project, @ref, :path => params[:path]), :class => "btn very_small", :target => "_blank"
= link_to "history", project_commits_path(@project, :path => params[:path], :ref => @ref), :class => "right", :style => "margin-right:10px;" = link_to "history", project_commits_path(@project, :path => params[:path], :ref => @ref), :class => "btn very_small"
= link_to "blame", blame_file_project_ref_path(@project, @ref, :path => params[:path]), :class => "btn very_small"
- if file.text? - if file.text?
- if name =~ /\.(md|markdown)$/i - if name =~ /\.(md|markdown)$/i
#tree-readme-holder #tree-readme-holder
......
= render "head"
#tree-holder
%ul.breadcrumb
%li
%span.arrow
= link_to tree_project_ref_path(@project, @ref, :path => nil) do
= @project.name
- @tree.breadcrumbs(6) do |link|
\/
%li= link
.clear
.view_file.blame_file
.view_file_header
%i.icon-file
%span.file_name
= @tree.name
%small blame
%span.options
= link_to "raw", blob_project_ref_path(@project, @ref, :path => params[:path]), :class => "btn very_small", :target => "_blank"
= link_to "history", project_commits_path(@project, :path => params[:path], :ref => @ref), :class => "btn very_small"
= link_to "source", tree_file_project_ref_path(@project, @ref, :path => params[:path]), :class => "btn very_small"
.view_file_content
%table
- @blame.each do |commit, lines|
- commit = Commit.new(commit)
%tr
%td.author
= image_tag gravatar_icon(commit.author_email, 16)
= commit.author_name
%td.commit
&nbsp;
= link_to project_commit_path(@project, :id => commit.id) do
%code= commit.id.to_s[0..10]
%span.row_title= truncate(commit.safe_message, :length => 30) rescue "--broken encoding"
%td.lines
= preserve do
%pre
- lines.each do |line|
= line
:javascript
$(function(){
$('.project-refs-select').chosen();
});
%ul.nav.nav-tabs = render "head"
%li
= form_tag switch_project_refs_path(@project), :method => :get, :class => "project-refs-form", :remote => true do
= select_tag "ref", grouped_options_refs, :onchange => "$(this.form).trigger('submit');", :class => "project-refs-select"
= hidden_field_tag :destination, "tree"
= hidden_field_tag :path, params[:path]
%li{:class => "#{'active' if (controller.controller_name == "refs") }"}
= link_to tree_project_ref_path(@project, @ref) do
Code
#tree-holder= render :partial => "tree", :locals => {:repo => @repo, :commit => @commit, :tree => @tree} #tree-holder= render :partial => "tree", :locals => {:repo => @repo, :commit => @commit, :tree => @tree}
:javascript :javascript
......
...@@ -94,6 +94,14 @@ Gitlab::Application.routes.draw do ...@@ -94,6 +94,14 @@ Gitlab::Application.routes.draw do
:id => /[a-zA-Z.0-9\/_\-]+/, :id => /[a-zA-Z.0-9\/_\-]+/,
:path => /.*/ :path => /.*/
} }
# blame
get "blame/:path" => "refs#blame",
:as => :blame_file,
:constraints => {
:id => /[a-zA-Z.0-9\/_\-]+/,
:path => /.*/
}
end end
end end
......
require 'spec_helper'
describe "Blame file" do
before { login_as :user }
describe "GET /:projectname/:commit/blob/Gemfile" do
before do
@project = Factory :project
@project.add_access(@user, :read)
visit tree_project_ref_path(@project, @project.root_ref, :path => "Gemfile")
click_link "blame"
end
it "should be correct path" do
current_path.should == blame_file_project_ref_path(@project, @project.root_ref, :path => "Gemfile")
end
it "should contain file view" do
page.should have_content("rubygems.org")
page.should have_content("Dmitriy Zaporozhets")
page.should have_content("bc3735004cb Moving to rails 3.2")
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment