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 64 @commit = Commit.new(older)
65 65 end
66 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 78 end
... ...
app/models/commit.rb
... ... @@ -19,6 +19,7 @@ class Commit
19 19 :diffs,
20 20 :tree,
21 21 :id,
  22 + :to_patch,
22 23 :to => :commit
23 24  
24 25  
... ...
app/views/commits/_commit_box.html.haml
1 1 .commit-box{class: @commit.parents.count > 1 ? "merge-commit" : ""}
2 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 15 %h3.commit-title
5 16 = commit_msg_with_link_to_issues(@project, @commit.title)
6 17 - if @commit.description.present?
... ...
config/routes.rb
... ... @@ -154,6 +154,10 @@ Gitlab::Application.routes.draw do
154 154 collection do
155 155 get :compare
156 156 end
  157 +
  158 + member do
  159 + get :patch
  160 + end
157 161 end
158 162 resources :team_members
159 163 resources :milestones
... ...