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
app/models/commit.rb
| ... | ... | @@ -82,20 +82,24 @@ class Commit |
| 82 | 82 | end |
| 83 | 83 | |
| 84 | 84 | def compare(project, from, to) |
| 85 | - first = project.commit(to.try(:strip)) | |
| 86 | - last = project.commit(from.try(:strip)) | |
| 87 | - | |
| 88 | 85 | result = { |
| 89 | 86 | commits: [], |
| 90 | 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 | 97 | if first && last |
| 95 | 98 | commits = [first, last].sort_by(&:created_at) |
| 96 | 99 | younger = commits.first |
| 97 | 100 | older = commits.last |
| 98 | 101 | |
| 102 | + result[:same] = (younger.id == older.id) | |
| 99 | 103 | result[:commits] = project.repo.commits_between(younger.id, older.id).map {|c| Commit.new(c)} |
| 100 | 104 | result[:diffs] = project.repo.diff(younger.id, older.id) rescue [] |
| 101 | 105 | result[:commit] = Commit.new(older) | ... | ... |
app/roles/repository.rb
| ... | ... | @@ -79,6 +79,14 @@ module Repository |
| 79 | 79 | @heads ||= repo.heads |
| 80 | 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 | 90 | def tree(fcommit, path = nil) |
| 83 | 91 | fcommit = commit if fcommit == :head |
| 84 | 92 | tree = fcommit.tree | ... | ... |
app/views/commits/compare.html.haml
| 1 | 1 | = render "head" |
| 2 | 2 | |
| 3 | -%h3 | |
| 3 | +%h3.page_title | |
| 4 | 4 | Compare View |
| 5 | 5 | %hr |
| 6 | 6 | |
| 7 | 7 | %div |
| 8 | - %p | |
| 8 | + %p.slead | |
| 9 | 9 | Fill input field with commit id like |
| 10 | - %code '4eedf23' | |
| 10 | + %code.label_branch 4eedf23 | |
| 11 | 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 | 15 | %br |
| 16 | 16 | |
| ... | ... | @@ -19,22 +19,24 @@ |
| 19 | 19 | = text_field_tag :from, params[:from], placeholder: "master", class: "xlarge" |
| 20 | 20 | = "..." |
| 21 | 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 | 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 | 29 | %div.ui-box |
| 28 | 30 | %h5.small Commits (#{@commits.count}) |
| 29 | 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 | 37 | :javascript |
| 36 | 38 | $(function() { |
| 37 | - var availableTags = #{@project.heads.map(&:name).to_json}; | |
| 39 | + var availableTags = #{@project.ref_names.to_json}; | |
| 38 | 40 | |
| 39 | 41 | $("#from").autocomplete({ |
| 40 | 42 | source: availableTags, |
| ... | ... | @@ -45,5 +47,7 @@ |
| 45 | 47 | source: availableTags, |
| 46 | 48 | minLength: 1 |
| 47 | 49 | }); |
| 50 | + | |
| 51 | + disableButtonIfEmptyField('#to', '.commits-compare-btn'); | |
| 48 | 52 | }); |
| 49 | 53 | ... | ... |