Commit 4cc169d3cacea7e4325bb5632cc8878a7c3f41fe
1 parent
49fe8fed
Exists in
master
and in
4 other branches
Improve commits compare. Added tags to autocomplete. Dont look for commits if from & to are empty
Showing
4 changed files
with
33 additions
and
16 deletions
Show diff stats
app/controllers/commits_controller.rb
@@ -52,6 +52,7 @@ class CommitsController < ApplicationController | @@ -52,6 +52,7 @@ class CommitsController < ApplicationController | ||
52 | @commits = result[:commits] | 52 | @commits = result[:commits] |
53 | @commit = result[:commit] | 53 | @commit = result[:commit] |
54 | @diffs = result[:diffs] | 54 | @diffs = result[:diffs] |
55 | + @refs_are_same = result[:same] | ||
55 | @line_notes = [] | 56 | @line_notes = [] |
56 | 57 | ||
57 | @commits = CommitDecorator.decorate(@commits) | 58 | @commits = CommitDecorator.decorate(@commits) |
app/models/commit.rb
@@ -82,20 +82,24 @@ class Commit | @@ -82,20 +82,24 @@ class Commit | ||
82 | end | 82 | end |
83 | 83 | ||
84 | def compare(project, from, to) | 84 | def compare(project, from, to) |
85 | - first = project.commit(to.try(:strip)) | ||
86 | - last = project.commit(from.try(:strip)) | ||
87 | - | ||
88 | result = { | 85 | result = { |
89 | commits: [], | 86 | commits: [], |
90 | diffs: [], | 87 | diffs: [], |
91 | - commit: nil | 88 | + commit: nil, |
89 | + same: false | ||
92 | } | 90 | } |
93 | 91 | ||
92 | + return result unless from && to | ||
93 | + | ||
94 | + first = project.commit(to.try(:strip)) | ||
95 | + last = project.commit(from.try(:strip)) | ||
96 | + | ||
94 | if first && last | 97 | if first && last |
95 | commits = [first, last].sort_by(&:created_at) | 98 | commits = [first, last].sort_by(&:created_at) |
96 | younger = commits.first | 99 | younger = commits.first |
97 | older = commits.last | 100 | older = commits.last |
98 | 101 | ||
102 | + result[:same] = (younger.id == older.id) | ||
99 | result[:commits] = project.repo.commits_between(younger.id, older.id).map {|c| Commit.new(c)} | 103 | result[:commits] = project.repo.commits_between(younger.id, older.id).map {|c| Commit.new(c)} |
100 | result[:diffs] = project.repo.diff(younger.id, older.id) rescue [] | 104 | result[:diffs] = project.repo.diff(younger.id, older.id) rescue [] |
101 | result[:commit] = Commit.new(older) | 105 | result[:commit] = Commit.new(older) |
app/roles/repository.rb
@@ -79,6 +79,14 @@ module Repository | @@ -79,6 +79,14 @@ module Repository | ||
79 | @heads ||= repo.heads | 79 | @heads ||= repo.heads |
80 | end | 80 | end |
81 | 81 | ||
82 | + def branches_names | ||
83 | + heads.map(&:name) | ||
84 | + end | ||
85 | + | ||
86 | + def ref_names | ||
87 | + [branches_names + tags].flatten | ||
88 | + end | ||
89 | + | ||
82 | def tree(fcommit, path = nil) | 90 | def tree(fcommit, path = nil) |
83 | fcommit = commit if fcommit == :head | 91 | fcommit = commit if fcommit == :head |
84 | tree = fcommit.tree | 92 | tree = fcommit.tree |
app/views/commits/compare.html.haml
1 | = render "head" | 1 | = render "head" |
2 | 2 | ||
3 | -%h3 | 3 | +%h3.page_title |
4 | Compare View | 4 | Compare View |
5 | %hr | 5 | %hr |
6 | 6 | ||
7 | %div | 7 | %div |
8 | - %p | 8 | + %p.slead |
9 | Fill input field with commit id like | 9 | Fill input field with commit id like |
10 | - %code '4eedf23' | 10 | + %code.label_branch 4eedf23 |
11 | or branch/tag name like | 11 | or branch/tag name like |
12 | - %code master | ||
13 | - & press compare button for commits list, code diff. | 12 | + %code.label_branch master |
13 | + and press compare button for commits list, code diff. | ||
14 | 14 | ||
15 | %br | 15 | %br |
16 | 16 | ||
@@ -19,22 +19,24 @@ | @@ -19,22 +19,24 @@ | ||
19 | = text_field_tag :from, params[:from], placeholder: "master", class: "xlarge" | 19 | = text_field_tag :from, params[:from], placeholder: "master", class: "xlarge" |
20 | = "..." | 20 | = "..." |
21 | = text_field_tag :to, params[:to], placeholder: "aa8b4ef", class: "xlarge" | 21 | = text_field_tag :to, params[:to], placeholder: "aa8b4ef", class: "xlarge" |
22 | + - if @refs_are_same | ||
23 | + .alert | ||
24 | + %span Refs are the same | ||
22 | .actions | 25 | .actions |
23 | - = submit_tag "Compare", class: "btn primary" | 26 | + = submit_tag "Compare", class: "btn primary wide commits-compare-btn" |
24 | 27 | ||
25 | - | ||
26 | -- unless @commits.empty? | 28 | +- if @commits.present? |
27 | %div.ui-box | 29 | %div.ui-box |
28 | %h5.small Commits (#{@commits.count}) | 30 | %h5.small Commits (#{@commits.count}) |
29 | %ul.unstyled= render @commits | 31 | %ul.unstyled= render @commits |
30 | 32 | ||
31 | -- unless @diffs.empty? | ||
32 | - %h4 Diff | ||
33 | - = render "commits/diffs", diffs: @diffs | 33 | + - unless @diffs.empty? |
34 | + %h4 Diff | ||
35 | + = render "commits/diffs", diffs: @diffs | ||
34 | 36 | ||
35 | :javascript | 37 | :javascript |
36 | $(function() { | 38 | $(function() { |
37 | - var availableTags = #{@project.heads.map(&:name).to_json}; | 39 | + var availableTags = #{@project.ref_names.to_json}; |
38 | 40 | ||
39 | $("#from").autocomplete({ | 41 | $("#from").autocomplete({ |
40 | source: availableTags, | 42 | source: availableTags, |
@@ -45,5 +47,7 @@ | @@ -45,5 +47,7 @@ | ||
45 | source: availableTags, | 47 | source: availableTags, |
46 | minLength: 1 | 48 | minLength: 1 |
47 | }); | 49 | }); |
50 | + | ||
51 | + disableButtonIfEmptyField('#to', '.commits-compare-btn'); | ||
48 | }); | 52 | }); |
49 | 53 |