diff options
| author | ruki <[email protected]> | 2024-01-25 08:59:48 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-01-25 08:59:48 +0800 |
| commit | 21aeb8d32ec1892904cc34a57e9c2c3d83b9f1bd (patch) | |
| tree | e4db21ca9e6c36940f1941ceeb72a009555df989 | |
| parent | 85bfb36d4e608662b74e5c42ac9e6a9052b3451e (diff) | |
| parent | 4bcf9cd00e87a544856b24c722112863cd962f6c (diff) | |
Merge pull request #4649 from SirLynix/improve-gitrepo
Fix CRLF issues with Git
| -rw-r--r-- | xmake/modules/devel/git/clone.lua | 9 | ||||
| -rw-r--r-- | xmake/modules/devel/git/pull.lua | 4 | ||||
| -rw-r--r-- | xmake/modules/private/action/require/impl/actions/patch_sources.lua | 2 | ||||
| -rw-r--r-- | xmake/modules/private/action/require/impl/repository.lua | 6 | ||||
| -rw-r--r-- | xmake/plugins/repo/main.lua | 6 |
5 files changed, 20 insertions, 7 deletions
diff --git a/xmake/modules/devel/git/clone.lua b/xmake/modules/devel/git/clone.lua index a1e7ca8eb..bdd02caf1 100644 --- a/xmake/modules/devel/git/clone.lua +++ b/xmake/modules/devel/git/clone.lua @@ -115,6 +115,15 @@ function main(url, opt) table.insert(argv, "core.fsmonitor=false") end + -- set core.autocrlf + if opt.autocrlf then + table.insert(argv, "-c") + table.insert(argv, "core.autocrlf=true") + elseif opt.autocrlf == false then + table.insert(argv, "-c") + table.insert(argv, "core.autocrlf=false") + end + -- set outputdir if opt.outputdir then table.insert(argv, path.translate(opt.outputdir)) diff --git a/xmake/modules/devel/git/pull.lua b/xmake/modules/devel/git/pull.lua index f68e32279..4488b7bed 100644 --- a/xmake/modules/devel/git/pull.lua +++ b/xmake/modules/devel/git/pull.lua @@ -68,6 +68,10 @@ function main(opt) table.insert(argv, "--tags") end + if opt.force then + table.insert(argv, "-f") + end + -- use proxy? local envs local proxy_conf = proxy.config() diff --git a/xmake/modules/private/action/require/impl/actions/patch_sources.lua b/xmake/modules/private/action/require/impl/actions/patch_sources.lua index 5306fbb9a..afa0336d7 100644 --- a/xmake/modules/private/action/require/impl/actions/patch_sources.lua +++ b/xmake/modules/private/action/require/impl/actions/patch_sources.lua @@ -28,7 +28,7 @@ import("devel.git") -- check sha256 function _check_sha256(patch_hash, patch_file) local ok = (patch_hash == hash.sha256(patch_file)) - if not ok and is_host("windows") then + if not ok then -- `git pull` maybe will replace lf to crlf in the patch text automatically on windows. -- so we need to attempt to fix this sha256 -- diff --git a/xmake/modules/private/action/require/impl/repository.lua b/xmake/modules/private/action/require/impl/repository.lua index 98cd45bd2..426a15e67 100644 --- a/xmake/modules/private/action/require/impl/repository.lua +++ b/xmake/modules/private/action/require/impl/repository.lua @@ -60,11 +60,11 @@ function _get_packagedir_from_locked_repo(packagename, locked_repo) local lastcommit if not os.isdir(repodir_local) then if repo_global then - git.clone(repo_global:directory(), {verbose = option.get("verbose"), outputdir = repodir_local}) + git.clone(repo_global:directory(), {verbose = option.get("verbose"), outputdir = repodir_local, autocrlf = false}) lastcommit = repo_global:commit() elseif network ~= "private" then local remoteurl = proxy.mirror(locked_repo.url) or locked_repo.url - git.clone(remoteurl, {verbose = option.get("verbose"), branch = locked_repo.branch, outputdir = repodir_local}) + git.clone(remoteurl, {verbose = option.get("verbose"), branch = locked_repo.branch, outputdir = repodir_local, autocrlf = false}) else wprint("we cannot lock repository(%s) in private network mode!", locked_repo.url) return @@ -84,7 +84,7 @@ function _get_packagedir_from_locked_repo(packagename, locked_repo) if network ~= "private" then -- pull the latest commit local remoteurl = proxy.mirror(locked_repo.url) or locked_repo.url - git.pull({verbose = option.get("verbose"), remote = remoteurl, branch = locked_repo.branch, repodir = repodir_local}) + git.pull({verbose = option.get("verbose"), remote = remoteurl, branch = locked_repo.branch, repodir = repodir_local, force = true}) -- 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 diff --git a/xmake/plugins/repo/main.lua b/xmake/plugins/repo/main.lua index 7c5d21ce8..ea4e132d3 100644 --- a/xmake/plugins/repo/main.lua +++ b/xmake/plugins/repo/main.lua @@ -52,7 +52,7 @@ function _add(name, url, branch, is_global) -- clone repository if not os.isdir(url) then local remoteurl = proxy.mirror(url) or url - git.clone(remoteurl, {verbose = option.get("verbose"), branch = branch, outputdir = repodir}) + git.clone(remoteurl, {verbose = option.get("verbose"), branch = branch, outputdir = repodir, autocrlf = false}) end -- add url @@ -115,13 +115,13 @@ function _update() -- only update the local repository with the remote url if not os.isdir(repo:url()) then vprint("pulling repository(%s): %s to %s ..", repo:name(), repo:url(), repodir) - git.pull({verbose = option.get("verbose"), branch = repo:branch(), repodir = repodir}) + git.pull({verbose = option.get("verbose"), branch = repo:branch(), repodir = repodir, force = true}) io.save(path.join(repodir, "updated"), {}) end else vprint("cloning repository(%s): %s to %s ..", repo:name(), repo:url(), repodir) local remoteurl = proxy.mirror(repo:url()) or repo:url() - git.clone(remoteurl, {verbose = option.get("verbose"), branch = repo:branch(), outputdir = repodir}) + git.clone(remoteurl, {verbose = option.get("verbose"), branch = repo:branch(), outputdir = repodir, autocrlf = false}) io.save(path.join(repodir, "updated"), {}) end pulled[repodir] = true |
