summaryrefslogtreecommitdiff
path: root/lua/lvim/utils/git.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/lvim/utils/git.lua')
-rw-r--r--lua/lvim/utils/git.lua53
1 files changed, 15 insertions, 38 deletions
diff --git a/lua/lvim/utils/git.lua b/lua/lvim/utils/git.lua
index 8f25a2bb..ce323160 100644
--- a/lua/lvim/utils/git.lua
+++ b/lua/lvim/utils/git.lua
@@ -1,11 +1,12 @@
local M = {}
local Log = require "lvim.core.log"
+local if_nil = vim.F.if_nil
local function git_cmd(opts)
local plenary_loaded, Job = pcall(require, "plenary.job")
if not plenary_loaded then
- vim.cmd "packadd plenary.nvim"
+ return 1, { "" }
end
opts = opts or {}
@@ -89,51 +90,27 @@ end
---Get the current Lunarvim development branch
---@return string|nil
function M.get_lvim_branch()
- local ret, branch = git_cmd { args = { "rev-parse", "--abbrev-ref", "HEAD" } }
- if ret ~= 0 or (not branch or branch[1] == "") then
- Log:error "Unable to retrieve the name of the current branch. Check the log for further information"
- return
- end
- return branch[1]
+ local _, results = git_cmd { args = { "rev-parse", "--abbrev-ref", "HEAD" } }
+ local branch = if_nil(results[1], "")
+ return branch
end
---Get currently checked-out tag of Lunarvim
----@param type string can be "short"
----@return string|nil
-function M.get_lvim_tag(type)
- type = type or ""
- local ret, results = git_cmd { args = { "describe", "--tags" } }
- local lvim_full_ver = results[1] or ""
+---@return string
+function M.get_lvim_tag()
+ local args = { "describe", "--tags", "--abbrev=0" }
- if ret ~= 0 or string.match(lvim_full_ver, "%d") == nil then
- return nil
- end
- if type == "short" then
- return vim.fn.split(lvim_full_ver, "-")[1]
- else
- return string.sub(lvim_full_ver, 1, #lvim_full_ver - 1)
- end
+ local _, results = git_cmd { args = args }
+ local tag = if_nil(results[1], "")
+ return tag
end
---Get the commit hash of currently checked-out commit of Lunarvim
----@param type string can be "short"
---@return string|nil
-function M.get_lvim_version(type)
- type = type or ""
- local branch = M.get_lvim_branch()
- if branch == "master" then
- return M.get_lvim_tag(type)
- end
- local ret, log_results = git_cmd { args = { "log", "--pretty=format:%h", "-1" } }
- local abbrev_version = log_results[1] or ""
- if ret ~= 0 or string.match(abbrev_version, "%d") == nil then
- Log:error "Unable to retrieve current version. Check the log for further information"
- return nil
- end
- if type == "short" then
- return abbrev_version
- end
- return branch .. "-" .. abbrev_version
+function M.get_lvim_current_sha()
+ local _, log_results = git_cmd { args = { "log", "--pretty=format:%h", "-1" } }
+ local abbrev_version = if_nil(log_results[1], "")
+ return abbrev_version
end
function M.generate_plugins_sha(output)