summaryrefslogtreecommitdiff
path: root/xmake/modules/devel/git/support.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2025-11-11 00:28:24 +0800
committerruki <[email protected]>2025-11-11 00:28:24 +0800
commita1637d473f01b372ea2dd1e038036ee756714fcb (patch)
treed3275717f173a16568d038b532b7bf9b41bc3f02 /xmake/modules/devel/git/support.lua
parent2d4595d2d0ac368f4606e30ad31489f6be8454d6 (diff)
add git support
Diffstat (limited to 'xmake/modules/devel/git/support.lua')
-rw-r--r--xmake/modules/devel/git/support.lua95
1 files changed, 95 insertions, 0 deletions
diff --git a/xmake/modules/devel/git/support.lua b/xmake/modules/devel/git/support.lua
new file mode 100644
index 000000000..5211d62d2
--- /dev/null
+++ b/xmake/modules/devel/git/support.lua
@@ -0,0 +1,95 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, Xmake Open Source Community.
+--
+-- @author ruki
+-- @file support.lua
+--
+
+-- imports
+import("core.base.option")
+import("core.base.semver")
+import("lib.detect.find_tool")
+
+-- get git version
+function _git_version()
+ local git_version = _g.git_version
+ if git_version == nil then
+ local git = assert(find_tool("git", {version = true}), "git not found!")
+ if git.version then
+ git_version = git.version
+ end
+ _g.git_version = git_version or false
+ end
+ return git_version or nil
+end
+
+-- can clone tag?
+-- @see https://github.com/xmake-io/xmake/issues/4151
+function can_clone_tag()
+ local can = _g.can_clone_tag
+ if can == nil then
+ local git_version = _git_version()
+ if git_version and semver.compare(git_version, "1.7.10") >= 0 then
+ can = true
+ end
+ _g.can_clone_tag = can or false
+ end
+ return can or false
+end
+
+-- can clone with --shallow-submodules?
+-- @see https://github.com/xmake-io/xmake/issues/4151
+function can_shallow_submodules()
+ local can = _g.can_shallow_submodules
+ if can == nil then
+ local git_version = _git_version()
+ if git_version and semver.compare(git_version, "2.9.0") >= 0 then
+ can = true
+ end
+ _g.can_shallow_submodules = can or false
+ end
+ return can or false
+end
+
+-- can clone with --filter=tree:0?
+-- @see https://github.com/xmake-io/xmake/issues/6246
+function can_treeless()
+ local can = _g.can_treeless
+ if can == nil then
+ local git_version = _git_version()
+ if git_version and semver.compare(git_version, "2.16.0") >= 0 then
+ can = true
+ end
+ _g.can_treeless = can or false
+ end
+ return can or false
+end
+
+-- can sparse checkout?
+-- @see https://github.com/xmake-io/xmake/issues/6071
+-- https://github.blog/open-source/git/bring-your-monorepo-down-to-size-with-sparse-checkout/
+function can_sparse_checkout()
+ local can = _g.can_sparse_checkout
+ if can == nil then
+ local git_version = _git_version()
+ if git_version and semver.compare(git_version, "2.25.0") >= 0 then
+ can = true
+ end
+ _g.can_sparse_checkout = can or false
+ end
+ return can or false
+end
+