summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/controllers/commits_controller.rb1
-rw-r--r--app/models/commit.rb12
-rw-r--r--app/roles/repository.rb8
-rw-r--r--app/views/commits/compare.html.haml28
4 files changed, 33 insertions, 16 deletions
diff --git a/app/controllers/commits_controller.rb b/app/controllers/commits_controller.rb
index 6d3f1aea6c9..1e7aec005f1 100644
--- a/app/controllers/commits_controller.rb
+++ b/app/controllers/commits_controller.rb
@@ -52,6 +52,7 @@ class CommitsController < ApplicationController
@commits = result[:commits]
@commit = result[:commit]
@diffs = result[:diffs]
+ @refs_are_same = result[:same]
@line_notes = []
@commits = CommitDecorator.decorate(@commits)
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 15afedcb101..73583e9e7b7 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -82,20 +82,24 @@ class Commit
end
def compare(project, from, to)
- first = project.commit(to.try(:strip))
- last = project.commit(from.try(:strip))
-
result = {
commits: [],
diffs: [],
- commit: nil
+ commit: nil,
+ same: false
}
+ return result unless from && to
+
+ first = project.commit(to.try(:strip))
+ last = project.commit(from.try(:strip))
+
if first && last
commits = [first, last].sort_by(&:created_at)
younger = commits.first
older = commits.last
+ result[:same] = (younger.id == older.id)
result[:commits] = project.repo.commits_between(younger.id, older.id).map {|c| Commit.new(c)}
result[:diffs] = project.repo.diff(younger.id, older.id) rescue []
result[:commit] = Commit.new(older)
diff --git a/app/roles/repository.rb b/app/roles/repository.rb
index a77de4ad5f0..01156ac18b7 100644
--- a/app/roles/repository.rb
+++ b/app/roles/repository.rb
@@ -79,6 +79,14 @@ module Repository
@heads ||= repo.heads
end
+ def branches_names
+ heads.map(&:name)
+ end
+
+ def ref_names
+ [branches_names + tags].flatten
+ end
+
def tree(fcommit, path = nil)
fcommit = commit if fcommit == :head
tree = fcommit.tree
diff --git a/app/views/commits/compare.html.haml b/app/views/commits/compare.html.haml
index 7dab1f5c0fa..db15ba53823 100644
--- a/app/views/commits/compare.html.haml
+++ b/app/views/commits/compare.html.haml
@@ -1,16 +1,16 @@
= render "head"
-%h3
+%h3.page_title
Compare View
%hr
%div
- %p
+ %p.slead
Fill input field with commit id like
- %code '4eedf23'
+ %code.label_branch 4eedf23
or branch/tag name like
- %code master
- &amp; press compare button for commits list, code diff.
+ %code.label_branch master
+ and press compare button for commits list, code diff.
%br
@@ -19,22 +19,24 @@
= text_field_tag :from, params[:from], placeholder: "master", class: "xlarge"
= "..."
= text_field_tag :to, params[:to], placeholder: "aa8b4ef", class: "xlarge"
+ - if @refs_are_same
+ .alert
+ %span Refs are the same
.actions
- = submit_tag "Compare", class: "btn primary"
+ = submit_tag "Compare", class: "btn primary wide commits-compare-btn"
-
-- unless @commits.empty?
+- if @commits.present?
%div.ui-box
%h5.small Commits (#{@commits.count})
%ul.unstyled= render @commits
-- unless @diffs.empty?
- %h4 Diff
- = render "commits/diffs", diffs: @diffs
+ - unless @diffs.empty?
+ %h4 Diff
+ = render "commits/diffs", diffs: @diffs
:javascript
$(function() {
- var availableTags = #{@project.heads.map(&:name).to_json};
+ var availableTags = #{@project.ref_names.to_json};
$("#from").autocomplete({
source: availableTags,
@@ -45,5 +47,7 @@
source: availableTags,
minLength: 1
});
+
+ disableButtonIfEmptyField('#to', '.commits-compare-btn');
});