return nil, "invalid sourceset"
end
+--- create a new git source repository
+-- @param c cache table
+-- @param lserver string: local server
+-- @param llocation string: working copy location on local server
+-- @param rserver string: remote server
+-- @param rlocation string: repository location on remote server
+-- @param flags: table of flags
+-- @return bool
+-- @return nil, or an error string on error
+function new_repository(c, lserver, llocation, rserver, rlocation, flags)
+ local rc, re
+ local e = new_error("setting up new git repository failed")
+ local lserver_url, re = cache.remote_url(c, lserver, llocation)
+ if not lserver_url then
+ return false, e:cat(re)
+ end
+ local lurl, re = url.parse(lserver_url)
+ if not lurl then
+ return false, e:cat(re)
+ end
+ local rc = e2lib.mkdir(string.format("/%s", lurl.path), "-p")
+ if not rc then
+ return false, e:cat("can't create path to local git repository")
+ end
+ rc = generic_git.git_init_db(c, lserver, llocation)
+ if not rc then
+ return false, e:cat("can't initialize local git repository")
+ end
+ rc = git.git_remote_add(c, lserver, llocation, "origin",
+ rserver, rlocation)
+ if not rc then
+ return false, e:cat("git remote add failed")
+ end
+ rc = e2lib.chdir("/"..lurl.path)
+ if not rc then
+ return false, e:cat(re)
+ end
+ local targs = {
+ string.format("'branch.master.remote' 'origin'"),
+ string.format("'branch.master.merge' 'refs/heads/master'"),
+ }
+ for _,args in ipairs(targs) do
+ rc, re = e2lib.git(".", "config", args)
+ if not rc then
+ return false, e:cat(re)
+ end
+ end
+ rc = generic_git.git_init_db(c, rserver, rlocation)
+ if not rc then
+ return false, e:cat("can't initialize remote git repository")
+ end
+ return true, nil
+end
+
return true, nil
end
---- create a new git source repository
--- @param c cache table
--- @param lserver string: local server
--- @param llocation string: working copy location on local server
--- @param rserver string: remote server
--- @param rlocation string: repository location on remote server
--- @param flags: table of flags
--- @return bool
--- @return nil, or an error string on error
-function git.new_git_source(c, lserver, llocation, rserver, rlocation, flags)
- local rc, re
- local e = new_error("setting up new git repository failed")
- local lserver_url, re = cache.remote_url(c, lserver, llocation)
- if not lserver_url then
- return false, e:cat(re)
- end
- local lurl, re = url.parse(lserver_url)
- if not lurl then
- return false, e:cat(re)
- end
- local rc = e2lib.mkdir(string.format("/%s", lurl.path), "-p")
- if not rc then
- return false, e:cat("can't create path to local git repository")
- end
- rc = generic_git.git_init_db(c, lserver, llocation)
- if not rc then
- return false, e:cat("can't initialize local git repository")
- end
- rc = git.git_remote_add(c, lserver, llocation, "origin",
- rserver, rlocation)
- if not rc then
- return false, e:cat("git remote add failed")
- end
- rc = e2lib.chdir("/"..lurl.path)
- if not rc then
- return false, e:cat(re)
- end
- local targs = {
- string.format("'branch.master.remote' 'origin'"),
- string.format("'branch.master.merge' 'refs/heads/master'"),
- }
- for _,args in ipairs(targs) do
- rc, re = e2lib.git(".", "config", args)
- if not rc then
- return false, e:cat(re)
- end
- end
- rc = generic_git.git_init_db(c, rserver, rlocation)
- if not rc then
- return false, e:cat("can't initialize remote git repository")
- end
- return true, nil
-end
-
--- create a table of lines for display
-- @param info the info structure
-- @param sourcename string
local lserver = info.root_server_name
local llocation = string.format("in/%s/.git", name)
local flags = {}
- local rc, re = e2scm["git"].new_git_source(info.cache, lserver, llocation,
+ local rc, re = generic_git.new_repository(info.cache, lserver, llocation,
rserver, rlocation, flags)
if not rc then
e2lib.abort(re)