summaryrefslogtreecommitdiff
path: root/xmake/modules/private/action/require/impl/repository.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2021-08-19 23:56:50 +0800
committerruki <[email protected]>2021-08-19 23:56:50 +0800
commitd96dd2ca564aca5ad0780feb9c14f57b76c693d2 (patch)
tree66e6447710a7956d4a1ca5900729bc0e159b67df /xmake/modules/private/action/require/impl/repository.lua
parent41213f3589000eb245aa33407ba971dbedc95c91 (diff)
lock repository
Diffstat (limited to 'xmake/modules/private/action/require/impl/repository.lua')
-rw-r--r--xmake/modules/private/action/require/impl/repository.lua54
1 files changed, 53 insertions, 1 deletions
diff --git a/xmake/modules/private/action/require/impl/repository.lua b/xmake/modules/private/action/require/impl/repository.lua
index 12a4772cf..b38bc95d3 100644
--- a/xmake/modules/private/action/require/impl/repository.lua
+++ b/xmake/modules/private/action/require/impl/repository.lua
@@ -19,12 +19,64 @@
--
-- imports
+import("core.base.option")
import("core.base.global")
+import("core.project.config")
import("core.package.repository")
+import("devel.git")
-- get package directory from the locked repository
function _get_packagedir_from_locked_repo(packagename, locked_repo)
--- print(packagename, locked_repo)
+ print(packagename, locked_repo)
+
+ -- find global repository directory
+ local repodir_global
+ for _, repo in ipairs(repositories()) do
+ if locked_repo.url == repo:url() and locked_repo.branch == repo:branch() then
+ repodir_global = repo:directory()
+ break
+ end
+ end
+
+ -- clone repository to local
+ local reponame = path.basename(locked_repo.url)
+ local repodir_local = path.join(config.directory(), "repositories", reponame)
+ if not os.isdir(repodir_local) then
+ if repodir_global then
+ git.clone(repodir_global, {verbose = option.get("verbose"), outputdir = repodir_local})
+ elseif global.get("network") ~= "private" then
+ git.clone(locked_repo.url, {verbose = option.get("verbose"), branch = locked_repo.branch, outputdir = repodir_local})
+ else
+ wprint("we cannot lock repository(%s) in private network mode!", locked_repo.url)
+ return
+ end
+ end
+
+ -- try checkout to the given commit
+ local ok = try {function () git.checkout(locked_repo.commit, {verbose = option.get("verbose"), repodir = repodir_local}); return true end}
+ if not ok then
+ if global.get("network") ~= "private" then
+ -- pull the latest commit
+ git.pull({verbose = option.get("verbose"), branch = locked_repo.branch, repodir = repodir_local})
+ -- re-checkout to the given commit
+ ok = try {function () git.checkout(locked_repo.commit, {verbose = option.get("verbose"), repodir = repodir_local}); return true end}
+ else
+ wprint("we cannot lock repository(%s) in private network mode!", locked_repo.url)
+ return
+ end
+ end
+
+ -- find package directory
+ local foundir
+ if ok then
+ local dir = path.join(repodir_local, "packages", packagename:sub(1, 1), packagename)
+ if os.isdir(dir) and os.isfile(path.join(dir, "xmake.lua")) then
+ local repo = repository.load(reponame, locked_repo.url, locked_repo.branch, false)
+ foundir = {dir, repo}
+ vprint("lock package(%s) in %s from repository(%s)/%s", packagename, dir, locked_repo.url, locked_repo.commit)
+ end
+ end
+ return foundir
end
-- get all repositories