Added projects. Part 6
This commit is contained in:
@@ -165,7 +165,11 @@ class GitRepo
|
||||
if repo.empty?
|
||||
@error = "Репозиторий пустой, нельзя добавить в проект пустой репозиторий"
|
||||
else
|
||||
#TODO clone repo
|
||||
if File.exist?(path)
|
||||
FileUtils.rm_rf(path, secure: true)
|
||||
end
|
||||
Dir.mkdir(path)
|
||||
Rugged::Repository.clone_at(repo.path, path)
|
||||
end
|
||||
else
|
||||
@error = "Файла репозитория не существует"
|
||||
@@ -176,4 +180,18 @@ class GitRepo
|
||||
end
|
||||
@error
|
||||
end
|
||||
|
||||
def is_repos_sync(repo_name, prj_repo_path)
|
||||
res = false
|
||||
repo = Rugged::Repository.new(prj_repo_path)
|
||||
File.open("locks/gitcreate", "r") do |f|
|
||||
f.flock(File::LOCK_SH)
|
||||
git_path = File.join(@path, repo_name + ".git")
|
||||
bare_repo = Rugged::Repository.new(git_path)
|
||||
pp bare_repo.head
|
||||
pp repo.head
|
||||
res = (bare_repo.head.oid == repo.head.oid)
|
||||
end
|
||||
res
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,6 +7,7 @@ PROJECTS_STRUCTURE = {
|
||||
:CONFIGS => "configs",
|
||||
:SRCPRP => "srcprp",
|
||||
:SIGNED => "signed",
|
||||
:SRC => "src",
|
||||
}
|
||||
|
||||
class ProjectsActions
|
||||
@@ -46,6 +47,18 @@ class ProjectsActions
|
||||
prj
|
||||
end
|
||||
|
||||
def get_project_path(id)
|
||||
@error = nil
|
||||
fname = nil
|
||||
prj = @db.proj(id)
|
||||
if prj.nil?
|
||||
@error = "Проекта с id = #{id} не существует"
|
||||
else
|
||||
fname = File.expand_path("#{prj[:projname]}.prj", @path)
|
||||
end
|
||||
fname
|
||||
end
|
||||
|
||||
def create_project(name, description, configuration)
|
||||
@error = nil
|
||||
ret_val = 0
|
||||
@@ -87,11 +100,43 @@ class ProjectsActions
|
||||
ret_val
|
||||
end
|
||||
|
||||
def get_project_gits(id)
|
||||
@db.get_gits_for_projects(id)
|
||||
def get_project_gits(id, repo)
|
||||
res = []
|
||||
File.open("locks/prjcreate", "r") do |f|
|
||||
f.flock(File::LOCK_EX)
|
||||
res = @db.get_gits_for_projects(id)
|
||||
res_sync = res.map do |item|
|
||||
prj_p = get_project_path(id)
|
||||
path = File.join(prj_p, PROJECTS_STRUCTURE[:SRC], item[:reponame])
|
||||
item[:is_repo_synced] = repo.is_repos_sync(item[:reponame], path)
|
||||
item
|
||||
end
|
||||
end
|
||||
res
|
||||
end
|
||||
|
||||
def add_git_to_project(prj_id, git_id)
|
||||
@db.save_git_project(prj_id, git_id)
|
||||
def add_git_to_project(prj_id, git_id, repo, git_name)
|
||||
path = get_project_path(prj_id)
|
||||
if @error.nil?
|
||||
path = File.join(path, PROJECTS_STRUCTURE[:SRC], git_name)
|
||||
err = repo.clone_repo_master(git_id, path)
|
||||
if err.nil?
|
||||
@db.save_git_project(prj_id, git_id)
|
||||
end
|
||||
else
|
||||
err = @error
|
||||
end
|
||||
err
|
||||
end
|
||||
|
||||
def renew_git_to_project(prj_id, git_id, repo, git_name)
|
||||
path = get_project_path(prj_id)
|
||||
if @error.nil?
|
||||
path = File.join(path, PROJECTS_STRUCTURE[:SRC], git_name)
|
||||
err = repo.clone_repo_master(git_id, path)
|
||||
else
|
||||
err = @error
|
||||
end
|
||||
err
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user