-<% form_tag({}, :method => :get) do %>
-<%= l(:label_revision) %>: <%= text_field_tag 'rev', @rev, :size => 5 %>
-<% end %>
+<%= render :partial => 'navigation' %>
-
<% form_tag({:action => 'revision', :id => @project}) do %>
-<%= l(:label_revision) %>: <%= text_field_tag 'rev', @rev, :size => 5 %>
+<%= l(:label_revision) %>: <%= text_field_tag 'rev', @rev, :size => 8 %>
<%= submit_tag 'OK' %>
<% end %>
diff --git a/app/views/repositories/show.rhtml b/app/views/repositories/show.rhtml
index a0f7dc3..18737ae 100644
--- a/app/views/repositories/show.rhtml
+++ b/app/views/repositories/show.rhtml
@@ -1,15 +1,10 @@
-
<%= call_hook(:view_repositories_show_contextual, { :repository => @repository, :project => @project }) %>
-<%= link_to l(:label_statistics), {:action => 'stats', :id => @project}, :class => 'icon icon-stats' %>
-<% if !@entries.nil? && authorize_for('repositories', 'browse') -%>
-<% form_tag({:action => 'browse', :id => @project}, :method => :get) do -%>
-| <%= l(:label_revision) %>: <%= text_field_tag 'rev', @rev, :size => 5 %>
-<% end -%>
-<% end -%>
+
+ <%= render :partial => 'navigation' %>
-
<%= l(:label_repository) %> (<%= @repository.scm_name %>)
+
<%= render :partial => 'breadcrumbs', :locals => { :path => @path, :kind => 'dir', :revision => @rev } %>
<% if !@entries.nil? && authorize_for('repositories', 'browse') %>
<%= render :partial => 'dir_list' %>
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 69f7c76..d559708 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -543,6 +543,7 @@ en:
label_browse: Browse
label_modification: "{{count}} change"
label_modification_plural: "{{count}} changes"
+ label_branch: Branch
label_revision: Revision
label_revision_plural: Revisions
label_associated_revisions: Associated revisions
diff --git a/config/routes.rb b/config/routes.rb
index bfacb1d..980d13d 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -218,7 +218,7 @@ ActionController::Routing::Routes.draw do |map|
repository_views.connect 'projects/:id/repository/revisions/:rev', :action => 'revision'
repository_views.connect 'projects/:id/repository/revisions/:rev/diff', :action => 'diff'
repository_views.connect 'projects/:id/repository/revisions/:rev/diff.:format', :action => 'diff'
- repository_views.connect 'projects/:id/repository/revisions/:rev/:action/*path'
+ repository_views.connect 'projects/:id/repository/revisions/:rev/:action/*path', :requirements => { :rev => /[a-z0-9.]+/ }
repository_views.connect 'projects/:id/repository/:action/*path'
end
diff --git a/lib/diff.rb b/lib/diff.rb
index 646f91b..f88e7fb 100644
--- a/lib/diff.rb
+++ b/lib/diff.rb
@@ -1,153 +1,155 @@
-class Diff
+module RedmineDiff
+ class Diff
- VERSION = 0.3
+ VERSION = 0.3
- def Diff.lcs(a, b)
- astart = 0
- bstart = 0
- afinish = a.length-1
- bfinish = b.length-1
- mvector = []
-
- # First we prune off any common elements at the beginning
- while (astart <= afinish && bstart <= afinish && a[astart] == b[bstart])
- mvector[astart] = bstart
- astart += 1
- bstart += 1
- end
-
- # now the end
- while (astart <= afinish && bstart <= bfinish && a[afinish] == b[bfinish])
- mvector[afinish] = bfinish
- afinish -= 1
- bfinish -= 1
- end
+ def Diff.lcs(a, b)
+ astart = 0
+ bstart = 0
+ afinish = a.length-1
+ bfinish = b.length-1
+ mvector = []
+
+ # First we prune off any common elements at the beginning
+ while (astart <= afinish && bstart <= afinish && a[astart] == b[bstart])
+ mvector[astart] = bstart
+ astart += 1
+ bstart += 1
+ end
+
+ # now the end
+ while (astart <= afinish && bstart <= bfinish && a[afinish] == b[bfinish])
+ mvector[afinish] = bfinish
+ afinish -= 1
+ bfinish -= 1
+ end
- bmatches = b.reverse_hash(bstart..bfinish)
- thresh = []
- links = []
-
- (astart..afinish).each { |aindex|
- aelem = a[aindex]
- next unless bmatches.has_key? aelem
- k = nil
- bmatches[aelem].reverse.each { |bindex|
- if k && (thresh[k] > bindex) && (thresh[k-1] < bindex)
- thresh[k] = bindex
- else
- k = thresh.replacenextlarger(bindex, k)
- end
- links[k] = [ (k==0) ? nil : links[k-1], aindex, bindex ] if k
+ bmatches = b.reverse_hash(bstart..bfinish)
+ thresh = []
+ links = []
+
+ (astart..afinish).each { |aindex|
+ aelem = a[aindex]
+ next unless bmatches.has_key? aelem
+ k = nil
+ bmatches[aelem].reverse.each { |bindex|
+ if k && (thresh[k] > bindex) && (thresh[k-1] < bindex)
+ thresh[k] = bindex
+ else
+ k = thresh.replacenextlarger(bindex, k)
+ end
+ links[k] = [ (k==0) ? nil : links[k-1], aindex, bindex ] if k
+ }
}
- }
- if !thresh.empty?
- link = links[thresh.length-1]
- while link
- mvector[link[1]] = link[2]
- link = link[0]
+ if !thresh.empty?
+ link = links[thresh.length-1]
+ while link
+ mvector[link[1]] = link[2]
+ link = link[0]
+ end
end
- end
- return mvector
- end
-
- def makediff(a, b)
- mvector = Diff.lcs(a, b)
- ai = bi = 0
- while ai < mvector.length
- bline = mvector[ai]
- if bline
- while bi < bline
- discardb(bi, b[bi])
- bi += 1
- end
- match(ai, bi)
- bi += 1
- else
- discarda(ai, a[ai])
- end
- ai += 1
- end
- while ai < a.length
- discarda(ai, a[ai])
- ai += 1
+ return mvector
end
- while bi < b.length
+
+ def makediff(a, b)
+ mvector = Diff.lcs(a, b)
+ ai = bi = 0
+ while ai < mvector.length
+ bline = mvector[ai]
+ if bline
+ while bi < bline
discardb(bi, b[bi])
bi += 1
end
match(ai, bi)
- 1
- end
-
- def compactdiffs
- diffs = []
- @diffs.each { |df|
- i = 0
- curdiff = []
- while i < df.length
- whot = df[i][0]
- s = @isstring ? df[i][2].chr : [df[i][2]]
- p = df[i][1]
- last = df[i][1]
- i += 1
- while df[i] && df[i][0] == whot && df[i][1] == last+1
- s << df[i][2]
- last = df[i][1]
- i += 1
- end
- curdiff.push [whot, p, s]
+ bi += 1
+ else
+ discarda(ai, a[ai])
+ end
+ ai += 1
end
- diffs.push curdiff
- }
- return diffs
- end
+ while ai < a.length
+ discarda(ai, a[ai])
+ ai += 1
+ end
+ while bi < b.length
+ discardb(bi, b[bi])
+ bi += 1
+ end
+ match(ai, bi)
+ 1
+ end
- attr_reader :diffs, :difftype
+ def compactdiffs
+ diffs = []
+ @diffs.each { |df|
+ i = 0
+ curdiff = []
+ while i < df.length
+ whot = df[i][0]
+ s = @isstring ? df[i][2].chr : [df[i][2]]
+ p = df[i][1]
+ last = df[i][1]
+ i += 1
+ while df[i] && df[i][0] == whot && df[i][1] == last+1
+ s << df[i][2]
+ last = df[i][1]
+ i += 1
+ end
+ curdiff.push [whot, p, s]
+ end
+ diffs.push curdiff
+ }
+ return diffs
+ end
- def initialize(diffs_or_a, b = nil, isstring = nil)
- if b.nil?
- @diffs = diffs_or_a
- @isstring = isstring
- else
- @diffs = []
+ attr_reader :diffs, :difftype
+
+ def initialize(diffs_or_a, b = nil, isstring = nil)
+ if b.nil?
+ @diffs = diffs_or_a
+ @isstring = isstring
+ else
+ @diffs = []
+ @curdiffs = []
+ makediff(diffs_or_a, b)
+ @difftype = diffs_or_a.class
+ end
+ end
+
+ def match(ai, bi)
+ @diffs.push @curdiffs unless @curdiffs.empty?
@curdiffs = []
- makediff(diffs_or_a, b)
- @difftype = diffs_or_a.class
end
- end
-
- def match(ai, bi)
- @diffs.push @curdiffs unless @curdiffs.empty?
- @curdiffs = []
- end
- def discarda(i, elem)
- @curdiffs.push ['-', i, elem]
- end
+ def discarda(i, elem)
+ @curdiffs.push ['-', i, elem]
+ end
- def discardb(i, elem)
- @curdiffs.push ['+', i, elem]
- end
+ def discardb(i, elem)
+ @curdiffs.push ['+', i, elem]
+ end
- def compact
- return Diff.new(compactdiffs)
- end
+ def compact
+ return Diff.new(compactdiffs)
+ end
- def compact!
- @diffs = compactdiffs
- end
+ def compact!
+ @diffs = compactdiffs
+ end
- def inspect
- @diffs.inspect
- end
+ def inspect
+ @diffs.inspect
+ end
+ end
end
module Diffable
def diff(b)
- Diff.new(self, b)
+ RedmineDiff::Diff.new(self, b)
end
# Create a hash that maps elements of the array to arrays of indices
@@ -158,9 +160,9 @@ module Diffable
range.each { |i|
elem = self[i]
if revmap.has_key? elem
- revmap[elem].push i
+ revmap[elem].push i
else
- revmap[elem] = [i]
+ revmap[elem] = [i]
end
}
return revmap
@@ -179,9 +181,9 @@ module Diffable
found = self[index]
return nil if value == found
if value > found
- low = index + 1
+ low = index + 1
else
- high = index
+ high = index
end
end
@@ -204,25 +206,25 @@ module Diffable
bi = 0
diff.diffs.each { |d|
d.each { |mod|
- case mod[0]
- when '-'
- while ai < mod[1]
- newary << self[ai]
- ai += 1
- bi += 1
- end
- ai += 1
- when '+'
- while bi < mod[1]
- newary << self[ai]
- ai += 1
- bi += 1
- end
- newary << mod[2]
- bi += 1
- else
- raise "Unknown diff action"
- end
+ case mod[0]
+ when '-'
+ while ai < mod[1]
+ newary << self[ai]
+ ai += 1
+ bi += 1
+ end
+ ai += 1
+ when '+'
+ while bi < mod[1]
+ newary << self[ai]
+ ai += 1
+ bi += 1
+ end
+ newary << mod[2]
+ bi += 1
+ else
+ raise "Unknown diff action"
+ end
}
}
while ai < self.length
@@ -243,38 +245,38 @@ class String
end
=begin
-= Diff
-(({diff.rb})) - computes the differences between two arrays or
-strings. Copyright (C) 2001 Lars Christensen
+ = Diff
+ (({diff.rb})) - computes the differences between two arrays or
+ strings. Copyright (C) 2001 Lars Christensen
-== Synopsis
+ == Synopsis
- diff = Diff.new(a, b)
- b = a.patch(diff)
+ diff = Diff.new(a, b)
+ b = a.patch(diff)
-== Class Diff
-=== Class Methods
---- Diff.new(a, b)
---- a.diff(b)
- Creates a Diff object which represent the differences between
- ((|a|)) and ((|b|)). ((|a|)) and ((|b|)) can be either be arrays
- of any objects, strings, or object of any class that include
- module ((|Diffable|))
+ == Class Diff
+ === Class Methods
+ --- Diff.new(a, b)
+ --- a.diff(b)
+ Creates a Diff object which represent the differences between
+ ((|a|)) and ((|b|)). ((|a|)) and ((|b|)) can be either be arrays
+ of any objects, strings, or object of any class that include
+ module ((|Diffable|))
-== Module Diffable
-The module ((|Diffable|)) is intended to be included in any class for
-which differences are to be computed. Diffable is included into String
-and Array when (({diff.rb})) is (({require}))'d.
+ == Module Diffable
+ The module ((|Diffable|)) is intended to be included in any class for
+ which differences are to be computed. Diffable is included into String
+ and Array when (({diff.rb})) is (({require}))'d.
-Classes including Diffable should implement (({[]})) to get element at
-integer indices, (({<<})) to append elements to the object and
-(({ClassName#new})) should accept 0 arguments to create a new empty
-object.
+ Classes including Diffable should implement (({[]})) to get element at
+ integer indices, (({<<})) to append elements to the object and
+ (({ClassName#new})) should accept 0 arguments to create a new empty
+ object.
-=== Instance Methods
---- Diffable#patch(diff)
- Applies the differences from ((|diff|)) to the object ((|obj|))
- and return the result. ((|obj|)) is not changed. ((|obj|)) and
- can be either an array or a string, but must match the object
- from which the ((|diff|)) was created.
+ === Instance Methods
+ --- Diffable#patch(diff)
+ Applies the differences from ((|diff|)) to the object ((|obj|))
+ and return the result. ((|obj|)) is not changed. ((|obj|)) and
+ can be either an array or a string, but must match the object
+ from which the ((|diff|)) was created.
=end
diff --git a/lib/redmine/scm/adapters/abstract_adapter.rb b/lib/redmine/scm/adapters/abstract_adapter.rb
index 7d21f8e..a1166aa 100644
--- a/lib/redmine/scm/adapters/abstract_adapter.rb
+++ b/lib/redmine/scm/adapters/abstract_adapter.rb
@@ -100,6 +100,14 @@ module Redmine
def entries(path=nil, identifier=nil)
return nil
end
+
+ def branches
+ return nil
+ end
+
+ def default_branch
+ return nil
+ end
def properties(path, identifier=nil)
return nil
@@ -260,6 +268,7 @@ module Redmine
class Revision
attr_accessor :identifier, :scmid, :name, :author, :time, :message, :paths, :revision, :branch
+
def initialize(attributes={})
self.identifier = attributes[:identifier]
self.scmid = attributes[:scmid]
@@ -271,7 +280,25 @@ module Redmine
self.revision = attributes[:revision]
self.branch = attributes[:branch]
end
-
+
+ def save(repo)
+ if repo.changesets.find_by_scmid(scmid.to_s).nil?
+ changeset = Changeset.create!(
+ :repository => repo,
+ :revision => identifier,
+ :scmid => scmid,
+ :committer => author,
+ :committed_on => time,
+ :comments => message)
+
+ paths.each do |file|
+ Change.create!(
+ :changeset => changeset,
+ :action => file[:action],
+ :path => file[:path])
+ end
+ end
+ end
end
class Annotate
diff --git a/lib/redmine/scm/adapters/git_adapter.rb b/lib/redmine/scm/adapters/git_adapter.rb
index a9e1dda..11ee1fb 100644
--- a/lib/redmine/scm/adapters/git_adapter.rb
+++ b/lib/redmine/scm/adapters/git_adapter.rb
@@ -16,128 +16,78 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
require 'redmine/scm/adapters/abstract_adapter'
+require 'grit'
+
+
module Redmine
module Scm
module Adapters
class GitAdapter < AbstractAdapter
-
+ attr_accessor :repo
+
# Git executable name
GIT_BIN = "git"
- # Get the revision of a particuliar file
- def get_rev (rev,path)
-
- if rev != 'latest' && !rev.nil?
- cmd="#{GIT_BIN} --git-dir #{target('')} show --date=iso --pretty=fuller #{shell_quote rev} -- #{shell_quote path}"
- else
- @branch ||= shellout("#{GIT_BIN} --git-dir #{target('')} branch") { |io| io.grep(/\*/)[0].strip.match(/\* (.*)/)[1] }
- cmd="#{GIT_BIN} --git-dir #{target('')} log --date=iso --pretty=fuller -1 #{@branch} -- #{shell_quote path}"
- end
- rev=[]
- i=0
- shellout(cmd) do |io|
- files=[]
- changeset = {}
- parsing_descr = 0 #0: not parsing desc or files, 1: parsing desc, 2: parsing files
-
- io.each_line do |line|
- if line =~ /^commit ([0-9a-f]{40})$/
- key = "commit"
- value = $1
- if (parsing_descr == 1 || parsing_descr == 2)
- parsing_descr = 0
- rev = Revision.new({:identifier => changeset[:commit],
- :scmid => changeset[:commit],
- :author => changeset[:author],
- :time => Time.parse(changeset[:date]),
- :message => changeset[:description],
- :paths => files
- })
- changeset = {}
- files = []
- end
- changeset[:commit] = $1
- elsif (parsing_descr == 0) && line =~ /^(\w+):\s*(.*)$/
- key = $1
- value = $2
- if key == "Author"
- changeset[:author] = value
- elsif key == "CommitDate"
- changeset[:date] = value
- end
- elsif (parsing_descr == 0) && line.chomp.to_s == ""
- parsing_descr = 1
- changeset[:description] = ""
- elsif (parsing_descr == 1 || parsing_descr == 2) && line =~ /^:\d+\s+\d+\s+[0-9a-f.]+\s+[0-9a-f.]+\s+(\w)\s+(.+)$/
- parsing_descr = 2
- fileaction = $1
- filepath = $2
- files << {:action => fileaction, :path => filepath}
- elsif (parsing_descr == 1) && line.chomp.to_s == ""
- parsing_descr = 2
- elsif (parsing_descr == 1)
- changeset[:description] << line
- end
- end
- rev = Revision.new({:identifier => changeset[:commit],
- :scmid => changeset[:commit],
- :author => changeset[:author],
- :time => (changeset[:date] ? Time.parse(changeset[:date]) : nil),
- :message => changeset[:description],
- :paths => files
- })
+ def initialize(*args)
+ args[1] = args[0]
+ super(*args)
+ begin
+ @repo = Grit::Repo.new(url, :is_bare => true)
+ rescue
+ Rails::logger.error "Repository could not be created"
end
+ end
- get_rev('latest',path) if rev == []
+ def info
+ begin
+ Info.new(:root_url => url, :lastrev => @repo.log('all', nil, :n => 1).first.to_revision)
+ rescue
+ nil
+ end
+ end
- return nil if $? && $?.exitstatus != 0
- return rev
+ def branches
+ @repo.branches
end
- def info
- revs = revisions(url,nil,nil,{:limit => 1})
- if revs && revs.any?
- Info.new(:root_url => url, :lastrev => revs.first)
- else
+ def default_branch
+ begin
+ @repo.default_branch
+ rescue
nil
end
- rescue Errno::ENOENT => e
- return nil
end
def entries(path=nil, identifier=nil)
- path ||= ''
+ return nil if repo.nil?
+ path = nil if path.empty?
+
entries = Entries.new
- cmd = "#{GIT_BIN} --git-dir #{target('')} ls-tree -l "
- cmd << shell_quote("HEAD:" + path) if identifier.nil?
- cmd << shell_quote(identifier + ":" + path) if identifier
- shellout(cmd) do |io|
- io.each_line do |line|
- e = line.chomp.to_s
- if e =~ /^\d+\s+(\w+)\s+([0-9a-f]{40})\s+([0-9-]+)\s+(.+)$/
- type = $1
- sha = $2
- size = $3
- name = $4
- entries << Entry.new({:name => name,
- :path => (path.empty? ? name : "#{path}/#{name}"),
- :kind => ((type == "tree") ? 'dir' : 'file'),
- :size => ((type == "tree") ? nil : size),
- :lastrev => get_rev(identifier,(path.empty? ? name : "#{path}/#{name}"))
-
- }) unless entries.detect{|entry| entry.name == name}
- end
- end
+
+ tree = repo.log(identifier, path, :n => 1).first.tree
+ tree = tree / path if path
+
+ tree.contents.each do |file|
+ file_path = path ? "#{path}/#{file.name}" : file.name
+ commit = repo.log(identifier, file_path, :n => 1).first
+
+ entries << Entry.new({
+ :name => file.name,
+ :path => file_path,
+ :kind => file.class == Grit::Blob ? 'file' : 'dir',
+ :size => file.respond_to?('size') ? file.size : nil,
+ :lastrev => commit.to_revision
+ })
end
- return nil if $? && $?.exitstatus != 0
+
entries.sort_by_name
end
-
+
def revisions(path, identifier_from, identifier_to, options={})
revisions = Revisions.new
- cmd = "#{GIT_BIN} --git-dir #{target('')} log --raw --date=iso --pretty=fuller"
+ cmd = "#{GIT_BIN} --git-dir #{target('')} log -M -C --all --raw --date=iso --pretty=fuller --no-merges"
cmd << " --reverse" if options[:reverse]
cmd << " -n #{options[:limit].to_i} " if (!options.nil?) && options[:limit]
cmd << " #{shell_quote(identifier_from + '..')} " if identifier_from
@@ -192,7 +142,7 @@ module Redmine
elsif (parsing_descr == 1)
changeset[:description] << line[4..-1]
end
- end
+ end
if changeset[:commit]
revision = Revision.new({:identifier => changeset[:commit],
@@ -213,7 +163,7 @@ module Redmine
return nil if $? && $?.exitstatus != 0
revisions
end
-
+
def diff(path, identifier_from, identifier_to=nil)
path ||= ''
if !identifier_to
@@ -265,6 +215,56 @@ module Redmine
end
end
end
-
end
+module Grit
+ class Repo
+ def log(commit = 'all', path = nil, options = {})
+ default_options = {:pretty => "raw", "no-merges" => true}
+ commit = default_branch if commit.nil?
+
+ if commit == 'all'
+ commit = default_branch
+ default_options.merge!(:all => true)
+ end
+
+ actual_options = default_options.merge(options)
+ arg = path ? [commit, '--', path] : [commit]
+ commits = self.git.log(actual_options, *arg)
+ Commit.list_from_string(self, commits)
+ end
+
+ def default_branch
+ if branches.map{|h| h.name}.include?('master')
+ 'master'
+ else
+ branches.first.name
+ end
+ end
+ end
+
+ class Diff
+ def action
+ return 'A' if new_file
+ return 'D' if deleted_file
+ return 'M'
+ end
+
+ def path
+ return a_path if a_path
+ return b_path if b_path
+ end
+ end
+
+ class Commit
+ def to_revision
+ Redmine::Scm::Adapters::Revision.new({
+ :identifier => id,
+ :scmid => id,
+ :author => "#{author.name} <#{author.email}>",
+ :time => committed_date,
+ :message => message
+ })
+ end
+ end
+end
diff --git a/public/javascripts/repository_navigation.js b/public/javascripts/repository_navigation.js
new file mode 100644
index 0000000..ded0256
--- /dev/null
+++ b/public/javascripts/repository_navigation.js
@@ -0,0 +1,31 @@
+Event.observe(window,'load',function() {
+ /*
+ If we're viewing a named branch, don't display it in the
+ revision box
+ */
+ if ($('rev').getValue() == $('branch').getValue()) {
+ $('rev').setValue('');
+ }
+
+ /*
+ Temporarily disable the revision box if the branch drop-down
+ is changed since both fields are named 'rev'
+ */
+ $('branch').observe('change',function(e) {
+ $('rev').disable();
+ e.element().parentNode.submit();
+ $('rev').enable();
+ })
+
+ /*
+ Temporarily disable the branch drop-down if 'Enter' is pressed
+ in the revision box since both fields are named 'rev'
+ */
+ $('rev').observe('keydown',function(e) {
+ if (e.keyCode == 13) {
+ $('branch').disable();
+ e.element().parentNode.submit();
+ $('branch').enable();
+ }
+ })
+})
diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css
index 813c8f1..88c5300 100644
--- a/public/stylesheets/application.css
+++ b/public/stylesheets/application.css
@@ -176,7 +176,7 @@ div.square {
width: .6em; height: .6em;
}
.contextual {float:right; white-space: nowrap; line-height:1.4em;margin-top:5px; padding-left: 10px; font-size:0.9em;}
-.contextual input {font-size:0.9em;}
+.contextual input,select {font-size:0.9em;}
.message .contextual { margin-top: 0; }
.splitcontentleft{float:left; width:49%;}
diff --git a/test/fixtures/repositories/git_repository.tar.gz b/test/fixtures/repositories/git_repository.tar.gz
index 84de88a..48966da 100644
Binary files a/test/fixtures/repositories/git_repository.tar.gz and b/test/fixtures/repositories/git_repository.tar.gz differ
diff --git a/test/functional/repositories_bazaar_controller_test.rb b/test/functional/repositories_bazaar_controller_test.rb
index b1787a5..98aa236 100644
--- a/test/functional/repositories_bazaar_controller_test.rb
+++ b/test/functional/repositories_bazaar_controller_test.rb
@@ -45,9 +45,9 @@ class RepositoriesBazaarControllerTest < Test::Unit::TestCase
end
def test_browse_root
- get :browse, :id => 3
+ get :show, :id => 3
assert_response :success
- assert_template 'browse'
+ assert_template 'show'
assert_not_nil assigns(:entries)
assert_equal 2, assigns(:entries).size
assert assigns(:entries).detect {|e| e.name == 'directory' && e.kind == 'dir'}
@@ -55,9 +55,9 @@ class RepositoriesBazaarControllerTest < Test::Unit::TestCase
end
def test_browse_directory
- get :browse, :id => 3, :path => ['directory']
+ get :show, :id => 3, :path => ['directory']
assert_response :success
- assert_template 'browse'
+ assert_template 'show'
assert_not_nil assigns(:entries)
assert_equal ['doc-ls.txt', 'document.txt', 'edit.png'], assigns(:entries).collect(&:name)
entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
@@ -67,9 +67,9 @@ class RepositoriesBazaarControllerTest < Test::Unit::TestCase
end
def test_browse_at_given_revision
- get :browse, :id => 3, :path => [], :rev => 3
+ get :show, :id => 3, :path => [], :rev => 3
assert_response :success
- assert_template 'browse'
+ assert_template 'show'
assert_not_nil assigns(:entries)
assert_equal ['directory', 'doc-deleted.txt', 'doc-ls.txt', 'doc-mkdir.txt'], assigns(:entries).collect(&:name)
end
@@ -102,7 +102,7 @@ class RepositoriesBazaarControllerTest < Test::Unit::TestCase
def test_directory_entry
get :entry, :id => 3, :path => ['directory']
assert_response :success
- assert_template 'browse'
+ assert_template 'show'
assert_not_nil assigns(:entry)
assert_equal 'directory', assigns(:entry).name
end
diff --git a/test/functional/repositories_cvs_controller_test.rb b/test/functional/repositories_cvs_controller_test.rb
index 2207d6a..c728bf3 100644
--- a/test/functional/repositories_cvs_controller_test.rb
+++ b/test/functional/repositories_cvs_controller_test.rb
@@ -51,9 +51,9 @@ class RepositoriesCvsControllerTest < Test::Unit::TestCase
end
def test_browse_root
- get :browse, :id => 1
+ get :show, :id => 1
assert_response :success
- assert_template 'browse'
+ assert_template 'show'
assert_not_nil assigns(:entries)
assert_equal 3, assigns(:entries).size
@@ -65,9 +65,9 @@ class RepositoriesCvsControllerTest < Test::Unit::TestCase
end
def test_browse_directory
- get :browse, :id => 1, :path => ['images']
+ get :show, :id => 1, :path => ['images']
assert_response :success
- assert_template 'browse'
+ assert_template 'show'
assert_not_nil assigns(:entries)
assert_equal ['add.png', 'delete.png', 'edit.png'], assigns(:entries).collect(&:name)
entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
@@ -78,9 +78,9 @@ class RepositoriesCvsControllerTest < Test::Unit::TestCase
def test_browse_at_given_revision
Project.find(1).repository.fetch_changesets
- get :browse, :id => 1, :path => ['images'], :rev => 1
+ get :show, :id => 1, :path => ['images'], :rev => 1
assert_response :success
- assert_template 'browse'
+ assert_template 'show'
assert_not_nil assigns(:entries)
assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
end
@@ -118,7 +118,7 @@ class RepositoriesCvsControllerTest < Test::Unit::TestCase
def test_directory_entry
get :entry, :id => 1, :path => ['sources']
assert_response :success
- assert_template 'browse'
+ assert_template 'show'
assert_not_nil assigns(:entry)
assert_equal 'sources', assigns(:entry).name
end
diff --git a/test/functional/repositories_darcs_controller_test.rb b/test/functional/repositories_darcs_controller_test.rb
index 8f1c7df..3f841e9 100644
--- a/test/functional/repositories_darcs_controller_test.rb
+++ b/test/functional/repositories_darcs_controller_test.rb
@@ -45,9 +45,9 @@ class RepositoriesDarcsControllerTest < Test::Unit::TestCase
end
def test_browse_root
- get :browse, :id => 3
+ get :show, :id => 3
assert_response :success
- assert_template 'browse'
+ assert_template 'show'
assert_not_nil assigns(:entries)
assert_equal 3, assigns(:entries).size
assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
@@ -56,9 +56,9 @@ class RepositoriesDarcsControllerTest < Test::Unit::TestCase
end
def test_browse_directory
- get :browse, :id => 3, :path => ['images']
+ get :show, :id => 3, :path => ['images']
assert_response :success
- assert_template 'browse'
+ assert_template 'show'
assert_not_nil assigns(:entries)
assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
@@ -69,9 +69,9 @@ class RepositoriesDarcsControllerTest < Test::Unit::TestCase
def test_browse_at_given_revision
Project.find(3).repository.fetch_changesets
- get :browse, :id => 3, :path => ['images'], :rev => 1
+ get :show, :id => 3, :path => ['images'], :rev => 1
assert_response :success
- assert_template 'browse'
+ assert_template 'show'
assert_not_nil assigns(:entries)
assert_equal ['delete.png'], assigns(:entries).collect(&:name)
end
diff --git a/test/functional/repositories_git_controller_test.rb b/test/functional/repositories_git_controller_test.rb
index 7f63ea3..bc9e6f4 100644
--- a/test/functional/repositories_git_controller_test.rb
+++ b/test/functional/repositories_git_controller_test.rb
@@ -46,22 +46,37 @@ class RepositoriesGitControllerTest < Test::Unit::TestCase
end
def test_browse_root
- get :browse, :id => 3
+ get :show, :id => 3
assert_response :success
- assert_template 'browse'
+ assert_template 'show'
assert_not_nil assigns(:entries)
- assert_equal 3, assigns(:entries).size
+ assert_equal 6, assigns(:entries).size
assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
+ assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
+ assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
+ assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
end
-
+
+ def test_browse_branch
+ get :show, :id => 3, :rev => 'test_branch'
+ assert_response :success
+ assert_template 'show'
+ assert_not_nil assigns(:entries)
+ assert_equal 4, assigns(:entries).size
+ assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
+ assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
+ assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
+ assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
+ end
+
def test_browse_directory
- get :browse, :id => 3, :path => ['images']
+ get :show, :id => 3, :path => ['images']
assert_response :success
- assert_template 'browse'
+ assert_template 'show'
assert_not_nil assigns(:entries)
- assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
+ assert_equal ['edit.png'], assigns(:entries).collect(&:name)
entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
assert_not_nil entry
assert_equal 'file', entry.kind
@@ -69,13 +84,28 @@ class RepositoriesGitControllerTest < Test::Unit::TestCase
end
def test_browse_at_given_revision
- get :browse, :id => 3, :path => ['images'], :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
+ get :show, :id => 3, :path => ['images'], :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
assert_response :success
- assert_template 'browse'
+ assert_template 'show'
assert_not_nil assigns(:entries)
assert_equal ['delete.png'], assigns(:entries).collect(&:name)
end
+=begin
+ Even with a rev param, this seems to render the list page rather than a single revision
+ assert_template 'revision' passes though...?
+
+ def test_view_revision
+ get :revisions, :id => 3, :rev => 'deff712f05a90d96edbd70facc47d944be5897e3'
+ assert_response :success
+ assert_template 'revision'
+ assert_tag :tag => 'h2', :child => "Revision #{assigns(:rev)[0,8]}"
+ assert_tag :tag => 'li',
+ :attributes => {:class => /change-A/},
+ :child => { :tag => 'a', :child => 'new_file.txt' }
+ end
+=end
+
def test_changes
get :changes, :id => 3, :path => ['images', 'edit.png']
assert_response :success
@@ -89,7 +119,7 @@ class RepositoriesGitControllerTest < Test::Unit::TestCase
assert_template 'entry'
# Line 19
assert_tag :tag => 'th',
- :content => /10/,
+ :content => /11/,
:attributes => { :class => /line-num/ },
:sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
end
@@ -104,7 +134,7 @@ class RepositoriesGitControllerTest < Test::Unit::TestCase
def test_directory_entry
get :entry, :id => 3, :path => ['sources']
assert_response :success
- assert_template 'browse'
+ assert_template 'show'
assert_not_nil assigns(:entry)
assert_equal 'sources', assigns(:entry).name
end
@@ -127,14 +157,14 @@ class RepositoriesGitControllerTest < Test::Unit::TestCase
assert_response :success
assert_template 'annotate'
# Line 23, changeset 2f9c0091
- assert_tag :tag => 'th', :content => /23/,
+ assert_tag :tag => 'th', :content => /24/,
:sibling => { :tag => 'td', :child => { :tag => 'a', :content => /2f9c0091/ } },
:sibling => { :tag => 'td', :content => /jsmith/ },
:sibling => { :tag => 'td', :content => /watcher =/ }
end
def test_annotate_binary_file
- get :annotate, :id => 3, :path => ['images', 'delete.png']
+ get :annotate, :id => 3, :path => ['images', 'edit.png']
assert_response 500
assert_tag :tag => 'div', :attributes => { :class => /error/ },
:content => /can not be annotated/
diff --git a/test/functional/repositories_mercurial_controller_test.rb b/test/functional/repositories_mercurial_controller_test.rb
index 53cbedd..6b097a2 100644
--- a/test/functional/repositories_mercurial_controller_test.rb
+++ b/test/functional/repositories_mercurial_controller_test.rb
@@ -45,9 +45,9 @@ class RepositoriesMercurialControllerTest < Test::Unit::TestCase
end
def test_browse_root
- get :browse, :id => 3
+ get :show, :id => 3
assert_response :success
- assert_template 'browse'
+ assert_template 'show'
assert_not_nil assigns(:entries)
assert_equal 3, assigns(:entries).size
assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
@@ -56,9 +56,9 @@ class RepositoriesMercurialControllerTest < Test::Unit::TestCase
end
def test_browse_directory
- get :browse, :id => 3, :path => ['images']
+ get :show, :id => 3, :path => ['images']
assert_response :success
- assert_template 'browse'
+ assert_template 'show'
assert_not_nil assigns(:entries)
assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
@@ -68,9 +68,9 @@ class RepositoriesMercurialControllerTest < Test::Unit::TestCase
end
def test_browse_at_given_revision
- get :browse, :id => 3, :path => ['images'], :rev => 0
+ get :show, :id => 3, :path => ['images'], :rev => 0
assert_response :success
- assert_template 'browse'
+ assert_template 'show'
assert_not_nil assigns(:entries)
assert_equal ['delete.png'], assigns(:entries).collect(&:name)
end
@@ -103,7 +103,7 @@ class RepositoriesMercurialControllerTest < Test::Unit::TestCase
def test_directory_entry
get :entry, :id => 3, :path => ['sources']
assert_response :success
- assert_template 'browse'
+ assert_template 'show'
assert_not_nil assigns(:entry)
assert_equal 'sources', assigns(:entry).name
end
diff --git a/test/functional/repositories_subversion_controller_test.rb b/test/functional/repositories_subversion_controller_test.rb
index e31094e..ac14385 100644
--- a/test/functional/repositories_subversion_controller_test.rb
+++ b/test/functional/repositories_subversion_controller_test.rb
@@ -47,18 +47,18 @@ class RepositoriesSubversionControllerTest < Test::Unit::TestCase
end
def test_browse_root
- get :browse, :id => 1
+ get :show, :id => 1
assert_response :success
- assert_template 'browse'
+ assert_template 'show'
assert_not_nil assigns(:entries)
entry = assigns(:entries).detect {|e| e.name == 'subversion_test'}
assert_equal 'dir', entry.kind
end
def test_browse_directory
- get :browse, :id => 1, :path => ['subversion_test']
+ get :show, :id => 1, :path => ['subversion_test']
assert_response :success
- assert_template 'browse'
+ assert_template 'show'
assert_not_nil assigns(:entries)
assert_equal ['folder', '.project', 'helloworld.c', 'textfile.txt'], assigns(:entries).collect(&:name)
entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'}
@@ -68,9 +68,9 @@ class RepositoriesSubversionControllerTest < Test::Unit::TestCase
end
def test_browse_at_given_revision
- get :browse, :id => 1, :path => ['subversion_test'], :rev => 4
+ get :show, :id => 1, :path => ['subversion_test'], :rev => 4
assert_response :success
- assert_template 'browse'
+ assert_template 'show'
assert_not_nil assigns(:entries)
assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'], assigns(:entries).collect(&:name)
end
@@ -131,7 +131,7 @@ class RepositoriesSubversionControllerTest < Test::Unit::TestCase
def test_directory_entry
get :entry, :id => 1, :path => ['subversion_test', 'folder']
assert_response :success
- assert_template 'browse'
+ assert_template 'show'
assert_not_nil assigns(:entry)
assert_equal 'folder', assigns(:entry).name
end
diff --git a/test/unit/git_adapter_test.rb b/test/unit/git_adapter_test.rb
new file mode 100644
index 0000000..0d7e597
--- /dev/null
+++ b/test/unit/git_adapter_test.rb
@@ -0,0 +1,22 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class GitAdapterTest < Test::Unit::TestCase
+ REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository'
+
+ if File.directory?(REPOSITORY_PATH)
+ def setup
+ @adapter = Redmine::Scm::Adapters::GitAdapter.new(REPOSITORY_PATH)
+ end
+
+ def test_branches
+ assert_equal @adapter.branches.map{|b| b.name}, ['master', 'test_branch']
+ end
+
+ def test_getting_all_revisions
+ assert_equal 11, @adapter.revisions('',nil,nil).length
+ end
+ else
+ puts "Git test repository NOT FOUND. Skipping unit tests !!!"
+ def test_fake; assert true end
+ end
+end
diff --git a/test/unit/repository_git_test.rb b/test/unit/repository_git_test.rb
index bc997b9..865f13a 100644
--- a/test/unit/repository_git_test.rb
+++ b/test/unit/repository_git_test.rb
@@ -34,8 +34,8 @@ class RepositoryGitTest < Test::Unit::TestCase
@repository.fetch_changesets
@repository.reload
- assert_equal 6, @repository.changesets.count
- assert_equal 11, @repository.changes.count
+ assert_equal 11, @repository.changesets.count
+ assert_equal 19, @repository.changes.count
commit = @repository.changesets.find(:first, :order => 'committed_on ASC')
assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments
@@ -57,10 +57,10 @@ class RepositoryGitTest < Test::Unit::TestCase
# Remove the 3 latest changesets
@repository.changesets.find(:all, :order => 'committed_on DESC', :limit => 3).each(&:destroy)
@repository.reload
- assert_equal 3, @repository.changesets.count
+ assert_equal 8, @repository.changesets.count
@repository.fetch_changesets
- assert_equal 6, @repository.changesets.count
+ assert_equal 11, @repository.changesets.count
end
else
puts "Git test repository NOT FOUND. Skipping unit tests !!!"