summaryrefslogtreecommitdiff
path: root/xmake/modules/devel/git/checkout.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2025-01-14 00:44:52 +0800
committerruki <[email protected]>2025-01-14 00:44:52 +0800
commit774980f0d1a660d3f33c97c2fe4d31fb5128f59e (patch)
treeccfc2da5e8371a2f3ef67fa224e902ee18cae5dc /xmake/modules/devel/git/checkout.lua
parent876fc4cf4ea813f4a24c83e2aebb504fe9c22c29 (diff)
support sparse-checkout for git
Diffstat (limited to 'xmake/modules/devel/git/checkout.lua')
-rw-r--r--xmake/modules/devel/git/checkout.lua10
1 files changed, 9 insertions, 1 deletions
diff --git a/xmake/modules/devel/git/checkout.lua b/xmake/modules/devel/git/checkout.lua
index 61919e422..38cc11845 100644
--- a/xmake/modules/devel/git/checkout.lua
+++ b/xmake/modules/devel/git/checkout.lua
@@ -20,6 +20,7 @@
-- imports
import("core.base.option")
+import("core.base.semver")
import("lib.detect.find_tool")
-- checkout to given branch, tag or commit
@@ -38,7 +39,7 @@ import("lib.detect.find_tool")
--
function main(commit, opt)
opt = opt or {}
- local git = assert(find_tool("git"), "git not found!")
+ local git = assert(find_tool("git", {version = true}), "git not found!")
local argv = {}
if opt.fsmonitor then
table.insert(argv, "-c")
@@ -48,6 +49,13 @@ function main(commit, opt)
table.insert(argv, "core.fsmonitor=false")
end
+ -- @see https://github.com/xmake-io/xmake/issues/6071
+ -- https://github.blog/open-source/git/bring-your-monorepo-down-to-size-with-sparse-checkout/
+ if opt.includes and git.version and semver.compare(git.version, "2.25") >= 0 then
+ os.vrunv(git.program, {"sparse-checkout", "init", "--cone"}, {curdir = opt.repodir})
+ os.vrunv(git.program, table.join({"sparse-checkout", "set"}, opt.includes), {curdir = opt.repodir})
+ end
+
table.insert(argv, "checkout")
table.insert(argv, commit)
os.vrunv(git.program, argv, {curdir = opt.repodir})