Commit 335f9d64105fc887e74b22922da58b2edb1bc809

Authored by randx
1 parent df6b587f

New Feature: Diff patch file export for commit

app/controllers/commits_controller.rb
@@ -64,4 +64,15 @@ class CommitsController < ApplicationController @@ -64,4 +64,15 @@ class CommitsController < ApplicationController
64 @commit = Commit.new(older) 64 @commit = Commit.new(older)
65 end 65 end
66 end 66 end
  67 +
  68 + def patch
  69 + @commit = project.commit(params[:id])
  70 +
  71 + send_data(
  72 + @commit.to_patch,
  73 + :type => "text/plain",
  74 + :disposition => 'attachment',
  75 + :filename => (@commit.id.to_s + ".patch")
  76 + )
  77 + end
67 end 78 end
app/models/commit.rb
@@ -19,6 +19,7 @@ class Commit @@ -19,6 +19,7 @@ class Commit
19 :diffs, 19 :diffs,
20 :tree, 20 :tree,
21 :id, 21 :id,
  22 + :to_patch,
22 :to => :commit 23 :to => :commit
23 24
24 25
app/views/commits/_commit_box.html.haml
1 .commit-box{class: @commit.parents.count > 1 ? "merge-commit" : ""} 1 .commit-box{class: @commit.parents.count > 1 ? "merge-commit" : ""}
2 .commit-head 2 .commit-head
3 - = link_to "Browse Code »", tree_project_ref_path(@project, @commit.id), :class => "browse-button" 3 + .right
  4 + = link_to tree_project_ref_path(@project, @commit.id), :class => "browse-button primary" do
  5 + %strong Browse Code »
  6 + - if @notes_count > 0
  7 + %span.btn.disabled
  8 + %i.icon-comment
  9 + = @notes_count
  10 +  
  11 + = link_to patch_project_commit_path(@project, @commit.id), :class => "btn small" do
  12 + %i.icon-download-alt
  13 + Get Patch
  14 +  
4 %h3.commit-title 15 %h3.commit-title
5 = commit_msg_with_link_to_issues(@project, @commit.title) 16 = commit_msg_with_link_to_issues(@project, @commit.title)
6 - if @commit.description.present? 17 - if @commit.description.present?
config/routes.rb
@@ -154,6 +154,10 @@ Gitlab::Application.routes.draw do @@ -154,6 +154,10 @@ Gitlab::Application.routes.draw do
154 collection do 154 collection do
155 get :compare 155 get :compare
156 end 156 end
  157 +
  158 + member do
  159 + get :patch
  160 + end
157 end 161 end
158 resources :team_members 162 resources :team_members
159 resources :milestones 163 resources :milestones