2011-11-10 23:51:19 +01:00
|
|
|
class Repository
|
|
|
|
attr_accessor :project
|
|
|
|
|
|
|
|
def self.default_ref
|
|
|
|
"master"
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(project)
|
|
|
|
@project = project
|
|
|
|
end
|
|
|
|
|
2011-11-15 09:34:30 +01:00
|
|
|
def path
|
2011-11-11 00:28:26 +01:00
|
|
|
@path ||= project.path
|
|
|
|
end
|
|
|
|
|
|
|
|
def project_id
|
|
|
|
project.id
|
|
|
|
end
|
|
|
|
|
2011-11-10 23:51:19 +01:00
|
|
|
def repo
|
|
|
|
@repo ||= Grit::Repo.new(project.path_to_repo)
|
|
|
|
end
|
|
|
|
|
2011-11-11 00:28:26 +01:00
|
|
|
def url_to_repo
|
2011-11-12 00:30:42 +01:00
|
|
|
if !GITOSIS["port"] or GITOSIS["port"] == 22
|
|
|
|
"#{GITOSIS["git_user"]}@#{GITOSIS["host"]}:#{path}.git"
|
|
|
|
else
|
|
|
|
"ssh://#{GITOSIS["git_user"]}@#{GITOSIS["host"]}:#{GITOSIS["port"]}/#{path}.git"
|
|
|
|
end
|
2011-11-11 00:28:26 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def path_to_repo
|
|
|
|
GITOSIS["base_path"] + path + ".git"
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_gitosis_project
|
|
|
|
Gitosis.new.configure do |c|
|
|
|
|
c.update_project(path, project.gitosis_writers)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy_gitosis_project
|
|
|
|
Gitosis.new.configure do |c|
|
|
|
|
c.destroy_project(@project)
|
|
|
|
end
|
2011-11-10 23:51:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def repo_exists?
|
|
|
|
repo rescue false
|
|
|
|
end
|
|
|
|
|
2011-11-11 00:28:26 +01:00
|
|
|
def tags
|
|
|
|
repo.tags.map(&:name).sort.reverse
|
|
|
|
end
|
|
|
|
|
|
|
|
def heads
|
|
|
|
@heads ||= repo.heads
|
2011-11-10 23:51:19 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def tree(fcommit, path = nil)
|
|
|
|
fcommit = commit if fcommit == :head
|
|
|
|
tree = fcommit.tree
|
|
|
|
path ? (tree / path) : tree
|
|
|
|
end
|
|
|
|
|
2011-11-11 00:28:26 +01:00
|
|
|
def commit(commit_id = nil)
|
|
|
|
if commit_id
|
|
|
|
repo.commits(commit_id).first
|
|
|
|
else
|
|
|
|
repo.commits.first
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-11-10 23:51:19 +01:00
|
|
|
def fresh_commits(n = 10)
|
|
|
|
commits = heads.map do |h|
|
2011-11-12 14:18:56 +01:00
|
|
|
repo.commits(h.name, n).each { |c| c.head = h }
|
2011-11-10 23:51:19 +01:00
|
|
|
end.flatten.uniq { |c| c.id }
|
|
|
|
|
|
|
|
commits.sort! do |x, y|
|
|
|
|
y.committed_date <=> x.committed_date
|
|
|
|
end
|
|
|
|
|
|
|
|
commits[0...n]
|
|
|
|
end
|
|
|
|
|
|
|
|
def commits_since(date)
|
|
|
|
commits = heads.map do |h|
|
2011-11-12 14:18:56 +01:00
|
|
|
repo.log(h.name, nil, :since => date).each { |c| c.head = h }
|
2011-11-10 23:51:19 +01:00
|
|
|
end.flatten.uniq { |c| c.id }
|
|
|
|
|
|
|
|
commits.sort! do |x, y|
|
|
|
|
y.committed_date <=> x.committed_date
|
|
|
|
end
|
|
|
|
|
|
|
|
commits
|
|
|
|
end
|
|
|
|
end
|