Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions packages/git/lde.json

This file was deleted.

115 changes: 0 additions & 115 deletions packages/git/src/init.lua

This file was deleted.

2 changes: 1 addition & 1 deletion packages/lde-core/lde.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"curl-sys": { "git": "https://github.com/lde-org/curl-sys" },
"semver": { "path": "../semver" },
"lde-test": { "path": "../lde-test" },
"git": { "path": "../git" },
"git2-sys": { "git": "https://github.com/lde-org/git2-sys" },
"rocked": { "path": "../rocked" },
"luarocks": { "path": "../luarocks" },
"archive": { "git": "https://github.com/lde-org/archive" },
Expand Down
24 changes: 17 additions & 7 deletions packages/lde-core/src/global/init.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local fs = require("fs")
local git = require("git")
local git2 = require("git2-sys")
local json = require("json")
local path = require("path")
local process = require("process")
Expand Down Expand Up @@ -100,12 +100,14 @@ function global.syncRegistry()

local registryDir = global.getRegistryDir()
if not fs.exists(registryDir) then
local ok, err = git.clone(global.getConfig().registry, registryDir)
if not ok then
local repo, err = git2.clone(global.getConfig().registry, registryDir)
if not repo then
error("Failed to clone lde registry: " .. (err or "unknown error"))
end
repo:updateSubmodules()
else
git.pull(registryDir)
local repo = git2.open(registryDir)
if repo then repo:pull() end
end
end

Expand Down Expand Up @@ -182,7 +184,14 @@ end
---@param commit string?
function global.cloneDir(repoName, repoUrl, branch, commit)
local repoDir = global.getGitRepoDir(repoName, branch, commit)
return git.clone(repoUrl, repoDir, branch, commit)
local repo, err = git2.clone(repoUrl, repoDir, branch)
if not repo then return nil, err end
repo:updateSubmodules()
if commit then
local ok, cerr = repo:checkout(commit)
if not ok then return nil, cerr end
end
return true
end

---@param repoName string
Expand Down Expand Up @@ -278,10 +287,11 @@ function global.getOrCloneRepo(repoName, cloneUrl, branch)
local safeName = branch and (repoName .. "-" .. branch) or repoName
local repoDir = global.getGitRepoDir(safeName)
if not fs.exists(repoDir) then
local ok, err = git.clone(cloneUrl, repoDir, branch)
if not ok then
local repo, err = git2.clone(cloneUrl, repoDir, branch)
if not repo then
error("Failed to clone git repository: " .. (err or "unknown error"))
end
repo:updateSubmodules()
end
return repoDir
end
Expand Down
13 changes: 7 additions & 6 deletions packages/lde-core/src/package/initialize.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ local path = require("path")
local fs = require("fs")
local util = require("util")
local ansi = require("ansi")
local git = require("git")
local git2 = require("git2-sys")

local Package = require("lde-core.package")

local function hasGit()
return git.version() == true
return true
end

---@param dir string
local function isInsideGitRepo(dir)
local ok = git.isInsideWorkTree(dir)
return ok == true
local repo = git2.open(dir)
if not repo then return false end
return repo:workdir() ~= nil
end

--- Initializes a package at the given directory.
Expand Down Expand Up @@ -79,8 +80,8 @@ local function initPackage(dir)
end

if hasGit() and not isInsideGitRepo(dir) then
local ok = git.init(dir)
if not ok then
local repo = git2.init(dir)
if not repo then
ansi.printf("{yellow}Warning: failed to initialize git repository")
end
end
Expand Down
14 changes: 9 additions & 5 deletions packages/lde-core/src/package/install/git.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local fs = require("fs")
local path = require("path")
local git = require("git")
local git2 = require("git2-sys")
local lde = require("lde-core")

---@param packageName string
Expand All @@ -11,11 +11,15 @@ local function resolve(packageName, depInfo)

local resolvedCommit = depInfo.commit
if not resolvedCommit then
local ok, output = git.getCommitHash(repoDir)
resolvedCommit = (ok and output) and string.gsub(output, "%s+$", "") or nil
if not resolvedCommit then
error("Failed to resolve HEAD commit for git dependency")
local repo, openErr = git2.open(repoDir)
if not repo then
error("Failed to resolve HEAD commit for git dependency: " .. (openErr or ""))
end
local sha, revErr = repo:revparse("HEAD")
if not sha then
error("Failed to resolve HEAD commit for git dependency: " .. (revErr or ""))
end
resolvedCommit = sha
end

---@type lde.Lockfile.GitDependency
Expand Down
13 changes: 9 additions & 4 deletions packages/lde-core/src/package/update.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
local fs = require("fs")
local json = require("json")
local git = require("git")
local git2 = require("git2-sys")
local semver = require("semver")
local luarocks = require("luarocks")

Expand All @@ -23,12 +23,17 @@ local function updateGitDependency(name, depInfo)
return false, "skipped (not installed)"
end

local ok, output = git.pull(repoDir)
local repo, openErr = git2.open(repoDir)
if not repo then
return false, "failed: " .. (openErr or "unknown error")
end

local ok, pullErr = repo:pull()
if not ok then
return false, "failed: " .. (output or "unknown error")
return false, "failed: " .. (pullErr or "unknown error")
end

return true, (string.gsub(output or "updated", "%s+$", ""))
return true, "updated"
end

--- Updates a registry dependency to the latest compatible version (same major).
Expand Down
6 changes: 4 additions & 2 deletions packages/lde-core/src/util/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ local util = {}

local fs = require("fs")
local path = require("path")
local git = require("git")
local git2 = require("git2-sys")
local json = require("json")
local rocked = require("rocked")
local ansi = require("ansi")
Expand Down Expand Up @@ -127,7 +127,9 @@ function util.openRockspecUrl(name, url, branch, commit)
if sourceUrl:match("^git") then
sourceUrl = util.normalizeGitUrl(sourceUrl)
dir = lde.global.getOrInitGitRepo(name, sourceUrl, branch or sourceTag, commit)
lockEntry = { git = sourceUrl, commit = select(2, git.getCommitHash(dir)) or commit, rockspec = url }
local repo = git2.open(dir)
local sha = repo and repo:revparse("HEAD")
lockEntry = { git = sourceUrl, commit = sha or commit, rockspec = url }
elseif sourceUrl:match("^https?://") then
dir = lde.global.getOrInitArchive(sourceUrl)
lockEntry = { archive = sourceUrl, rockspec = url }
Expand Down
1 change: 0 additions & 1 deletion packages/lde-core/tests/main.test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ local fs = require("fs")
local env = require("env")
local path = require("path")
local json = require("json")
local git = require("git")

local lde = require("lde-core")

Expand Down
2 changes: 1 addition & 1 deletion packages/lde/lde.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"git": "https://github.com/codebycruz/winapi",
"optional": true
},
"git": { "path": "../git" },
"git2-sys": { "git": "https://github.com/lde-org/git2-sys" },
"luarocks": { "path": "../luarocks" },
"readline": { "path": "../readline" }
},
Expand Down
22 changes: 10 additions & 12 deletions packages/lde/src/commands/publish.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
local ansi = require("ansi")
local git = require("git")
local git2 = require("git2-sys")
local json = require("json")
local process = require("process")

Expand Down Expand Up @@ -28,14 +28,6 @@ local function openBrowser(url)
end
end

---@param ok boolean
---@param output string?
---@return string?
local function trimOutput(ok, output)
if not ok or not output then return nil end
return (string.gsub(output, "%s+$", ""))
end

---@param args clap.Args
local function publish(args)
local pkg, err = lde.Package.open()
Expand All @@ -47,19 +39,25 @@ local function publish(args)
local config = pkg:readConfig()
local pkgDir = pkg:getDir()

local gitUrl = trimOutput(git.remoteGetUrl("origin", pkgDir))
local repo, repoErr = git2.open(pkgDir)
if not repo then
ansi.printf("{red}Could not open git repository: %s", repoErr or "unknown error")
return
end

local gitUrl, urlErr = repo:remoteUrl("origin")
if not gitUrl then
ansi.printf("{red}Could not get git remote URL. Is this a git repo with an 'origin' remote?")
return
end

local commit = trimOutput(git.getCommitHash(pkgDir))
local commit, commitErr = repo:revparse("HEAD")
if not commit then
ansi.printf("{red}Could not get current commit. Does this repo have any commits?")
return
end

local branch = trimOutput(git.getCurrentBranch(pkgDir)) or "master"
local branch = repo:currentBranch() or "master"

local versions = {}
json.addField(versions, config.version, commit)
Expand Down
4 changes: 2 additions & 2 deletions packages/lde/tests/main.test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ local fs = require("fs")
local env = require("env")
local path = require("path")
local json = require("json")
local git = require("git")
local git2 = require("git2-sys")

local lde = require("lde-core")

Expand All @@ -15,7 +15,7 @@ test.it("should not ignore --git in ldx", function()
local repoDir = lde.global.getGitRepoDir("hood")
fs.rmdir(repoDir)
fs.mkdir(repoDir)
git.init(repoDir, true)
git2.init(repoDir, true)
fs.write(path.join(repoDir, "lde.json"), json.encode({
name = "hood",
version = "1.0.0",
Expand Down