--- functions with '1' postfix take url strings as parameter. the others
-- take server / location
-module("generic_git", package.seeall)
+local generic_git = {}
local cache = require("cache")
--- clone a git repository
-- @param skip_checkout bool: pass -n to git clone?
-- @return true on success, false on error
-- @return nil, an error object on failure
-function git_clone_url1(surl, location, destdir, skip_checkout)
+function generic_git.git_clone_url1(surl, location, destdir, skip_checkout)
if (not surl) or (not location) or (not destdir) then
e2lib.abort("git_clone_url1(): missing parameter")
end
if not u then
return false, e:cat(re)
end
- local src, re = git_url1(u)
+ local src, re = generic_git.git_url1(u)
if not src then
return false, e:cat(re)
end
-- @param start_point string: where to start the branch
-- @return bool
-- @return nil, an error object on failure
-function git_branch_new1(gitwc, track, branch, start_point)
+function generic_git.git_branch_new1(gitwc, track, branch, start_point)
-- git branch [--track|--no-track] <branch> <start_point>
local f_track = nil
if track == true then
-- @param branch name of the branch to checkout
-- @return bool
-- @return an error object on failure
-function git_checkout1(gitwc, branch)
+function generic_git.git_checkout1(gitwc, branch)
e2lib.log(3, string.format("checking out branch: %s", branch))
-- git checkout <branch>
local cmd = string.format("cd %s && git checkout %s", e2lib.shquote(gitwc),
-- @param ref string: a reference, according to the git manual
-- @return string: the commit id matching the ref parameter, or nil on error
-- @return an error object on failure
-function git_rev_list1(gitdir, ref)
+function generic_git.git_rev_list1(gitdir, ref)
e2lib.log(4, string.format("git_rev_list(): %s %s",
tostring(gitdir), tostring(ref)))
local e = new_error("git rev-list failed")
-- @param rurl string: remote url
-- @return bool
-- @return an error object on failure
-function git_init_db1(rurl)
+function generic_git.git_init_db1(rurl)
if (not rurl) then
e2lib.abort("git_init_db1(): missing parameter")
end
-- @param refspec string: a git refspec
-- @return bool
-- @return an error object on failure
-function git_push1(gitdir, rurl, refspec)
+function generic_git.git_push1(gitdir, rurl, refspec)
if (not rurl) or (not gitdir) or (not refspec) then
e2lib.abort("git_push1(): missing parameter")
end
if not u then
return false, e:cat(re)
end
- local remote_git_url, re = git_url1(u)
+ local remote_git_url, re = generic_git.git_url1(u)
if not remote_git_url then
return false, e:cat(re)
end
-- @param name string: remote name
-- @return bool
-- @return an error object on failure
-function git_remote_add1(lurl, rurl, name)
+function generic_git.git_remote_add1(lurl, rurl, name)
if (not lurl) or (not rurl) or (not name) then
e2lib.abort("missing parameter")
end
if not rrepo then
return false, e:cat(re)
end
- local giturl, re = git_url1(rrepo)
+ local giturl, re = generic_git.git_url1(rrepo)
if not giturl then
return false, e:cat(re)
end
-- @param u url table
-- @return string: the git url
-- @return an error object on failure
-function git_url1(u)
+function generic_git.git_url1(u)
e2lib.log(4, string.format("git_url(%s)", tostring(u)))
local giturl
if u.transport == "ssh" or u.transport == "scp" or
-- @param skip_checkout bool: pass -n to git clone?
-- @return bool
-- @return an error object on failure
-function git_clone_from_server(c, server, location, destdir,
+function generic_git.git_clone_from_server(c, server, location, destdir,
skip_checkout)
local rc, re
local e = new_error("cloning git repository")
if not surl then
return false, e:cat(re)
end
- local rc, re = git_clone_url1(surl, "", destdir, skip_checkout)
+ local rc, re = generic_git.git_clone_url1(surl, "", destdir, skip_checkout)
if not rc then
return false, re
end
-- @param location string: location
-- @return bool
-- @return an error object on failure
-function git_init_db(c, server, location)
+function generic_git.git_init_db(c, server, location)
local rc, re
local e = new_error("initializing git repository")
local rurl, re = cache.remote_url(c, server, location)
if not rurl then
return false, e:cat(re)
end
- local rc, re = git_init_db1(rurl)
+ local rc, re = generic_git.git_init_db1(rurl)
if not rc then
return false, re
end
-- @param refspec string: a git refspec
-- @return bool
-- @return an error object on failure
-function git_push(c, gitdir, server, location, refspec)
+function generic_git.git_push(c, gitdir, server, location, refspec)
local rc, re
local e = new_error("git push failed")
local rurl, re = cache.remote_url(c, server, location)
if not rurl then
return false, e:cat(re)
end
- return git_push1(gitdir, rurl, refspec)
+ return generic_git.git_push1(gitdir, rurl, refspec)
end
--- do a git config query
-- @param query string: query to pass to git config
-- @return string: the value printed to stdout by git config, or nil
-- @return an error object on failure
-function git_config(gitdir, query)
+function generic_git.git_config(gitdir, query)
local rc, re
local e = new_error("running git config")
local tmpfile = e2lib.mktempfile()
-- @param args string: args to pass to git add
-- @return bool
-- @return an error object on failure
-function git_add(gitdir, args)
+function generic_git.git_add(gitdir, args)
local rc, re
local e = new_error("running git add")
if not gitdir then
-- @param args string: args to pass to git add
-- @return bool
-- @return an error object on failure
-function git_commit(gitdir, args)
+function generic_git.git_commit(gitdir, args)
local rc, re
local e = new_error("git commit failed")
return e2lib.git("commit", gitdir, args)
-- @param tag string: tag name
-- @return bool, or nil on error
-- @return an error object on failure
-function verify_remote_tag(gitdir, tag)
+function generic_git.verify_remote_tag(gitdir, tag)
e2lib.logf(4, "generic_git.verify_remote_tag(%s, %s)", tostring(gitdir),
tostring(tag))
local e = new_error("verifying remote tag")
end
-- store commit ids for use in the error message, if any
- local lrev = git_rev_list1(gitdir, tag)
+ local lrev = generic_git.git_rev_list1(gitdir, tag)
if not lrev then
return nil, e:cat(re)
end
- local rrev = git_rev_list1(gitdir, rtag)
+ local rrev = generic_git.git_rev_list1(gitdir, rtag)
if not rrev then
return nil, e:cat(re)
end
-- @param gitwc string: path to a git working tree (default: .)
-- @return bool, or nil on error
-- @return an error object on failure
-function verify_clean_repository(gitwc)
+function generic_git.verify_clean_repository(gitwc)
e2lib.logf(4, "generic_git.verify_clean_repository(%s)", tostring(gitwc))
gitwc = gitwc or "."
local e = new_error("verifying that repository is clean")
-- @param tag string: tag name
-- @return bool, or nil on error
-- @return an error object on failure
-function verify_head_match_tag(gitwc, verify_tag)
+function generic_git.verify_head_match_tag(gitwc, verify_tag)
e2lib.logf(4, "generic_git.verify_head_match_tag(%s, %s)", tostring(gitwc),
tostring(verify_tag))
assert(verify_tag)
return true
end
-function sourceset2ref(sourceset, branch, tag)
+function generic_git.sourceset2ref(sourceset, branch, tag)
if sourceset == "branch" or
(sourceset == "lazytag" and tag == "^") then
return string.format("refs/heads/%s", branch)
-- @param flags: table of flags
-- @return bool
-- @return nil, or an error string on error
-function new_repository(c, lserver, llocation, rserver, rlocation, flags)
+function generic_git.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)
return true, nil
end
+return generic_git