Skip to content

Commit

Permalink
Merge pull request #4909 from xmake-io/longpaths
Browse files Browse the repository at this point in the history
enable longpaths for submodule/reset #4905
  • Loading branch information
waruqi committed Apr 1, 2024
2 parents 479ebb1 + c30d3a6 commit 0a6b495
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
24 changes: 20 additions & 4 deletions xmake/modules/devel/git/submodule/reset.lua
Expand Up @@ -36,11 +36,7 @@ import("lib.detect.find_tool")
-- @endcode
--
function main(opt)

-- init options
opt = opt or {}

-- find git
local git = assert(find_tool("git"), "git not found!")

-- init argv
Expand Down Expand Up @@ -79,6 +75,26 @@ function main(opt)
table.insert(argv, opt.commit)
end

-- enable long paths
local longpaths_old
local longpaths_changed = false
if opt.longpaths then
local longpaths_old = try {function () return os.iorunv(git.program, {"config", "--get", "--global", "core.longpaths"}, {curdir = opt.repodir}) end}
if not longpaths_old or not longpaths_old:find("true") then
os.vrunv(git.program, {"config", "--global", "core.longpaths", "true"}, {curdir = opt.repodir})
longpaths_changed = true
end
end

-- reset it
os.vrunv(git.program, argv, {curdir = opt.repodir})

-- restore old long paths configuration
if longpaths_changed then
if longpaths_old and longpaths_old:find("false") then
os.vrunv(git.program, {"config", "--global", "core.longpaths", "false"}, {curdir = opt.repodir})
else
os.vrunv(git.program, {"config", "--global", "--unset", "core.longpaths"}, {curdir = opt.repodir})
end
end
end
4 changes: 0 additions & 4 deletions xmake/modules/devel/git/submodule/update.lua
Expand Up @@ -36,11 +36,7 @@ import("lib.detect.find_tool")
-- @endcode
--
function main(opt)

-- init options
opt = opt or {}

-- find git
local git = assert(find_tool("git"), "git not found!")

-- init argv
Expand Down
10 changes: 5 additions & 5 deletions xmake/modules/private/action/require/impl/actions/download.lua
Expand Up @@ -38,6 +38,9 @@ import("utils.archive")
function _checkout(package, url, sourcedir, opt)
opt = opt or {}

-- we need to enable longpaths on windows
local longpaths = package:policy("platform.longpaths")

-- use previous source directory if exists
local packagedir = path.join(sourcedir, package:name())
if os.isdir(path.join(packagedir, ".git")) and
Expand All @@ -50,7 +53,7 @@ function _checkout(package, url, sourcedir, opt)
-- clean and reset submodules
if os.isfile(path.join(packagedir, ".gitmodules")) then
git.submodule.clean({repodir = packagedir, force = true, all = true})
git.submodule.reset({repodir = packagedir, hard = true})
git.submodule.reset({repodir = packagedir, hard = true, longpaths = longpaths})
end
tty.erase_line_to_start().cr()
return
Expand All @@ -71,7 +74,7 @@ function _checkout(package, url, sourcedir, opt)
git.reset({repodir = localdir, hard = true})
if os.isfile(path.join(localdir, ".gitmodules")) then
git.submodule.clean({repodir = localdir, force = true, all = true})
git.submodule.reset({repodir = localdir, hard = true})
git.submodule.reset({repodir = localdir, hard = true, longpaths = longpaths})
end
os.cp(localdir, packagedir)
tty.erase_line_to_start().cr()
Expand All @@ -81,9 +84,6 @@ function _checkout(package, url, sourcedir, opt)
-- remove temporary directory
os.rm(sourcedir .. ".tmp")

-- we need to enable longpaths on windows
local longpaths = package:policy("platform.longpaths")

-- download package from branches?
packagedir = path.join(sourcedir .. ".tmp", package:name())
local branch = package:branch()
Expand Down

0 comments on commit 0a6b495

Please sign in to comment.