| 1 |
class TreesController < ApplicationController |
| 2 |
before_filter :find_project_and_repository |
| 3 |
before_filter :check_repository_for_commits |
| 4 |
|
| 5 |
def index |
| 6 |
redirect_to(project_repository_tree_path(@project, @repository, |
| 7 |
@repository.head_candidate.name, [])) |
| 8 |
end |
| 9 |
|
| 10 |
def show |
| 11 |
@git = @repository.git |
| 12 |
@commit = @git.commit(params[:id]) |
| 13 |
unless @commit |
| 14 |
redirect_to project_repository_tree_path(@project, @repository, "HEAD", params[:path]) |
| 15 |
return |
| 16 |
end |
| 17 |
path = params[:path].blank? ? [] : ["#{params[:path].join("/")}/"] |
| 18 |
@tree = @git.tree(@commit.tree.id, path) |
| 19 |
end |
| 20 |
|
| 21 |
def archive |
| 22 |
@git = @repository.git |
| 23 |
@commit = @git.commit(params[:id]) |
| 24 |
|
| 25 |
if @commit |
| 26 |
prefix = "#{@project.slug}-#{@repository.name}" |
| 27 |
data = @git.archive_tar_gz(params[:id], prefix + "/") |
| 28 |
send_data(data, :type => 'application/x-gzip', |
| 29 |
:filename => "#{prefix}.tar.gz") |
| 30 |
else |
| 31 |
flash[:error] = "The given repository or sha is invalid" |
| 32 |
redirect_to project_repository_path(@project, @repository) and return |
| 33 |
end |
| 34 |
end |
| 35 |
end |