diff options
author | kylo252 <[email protected]> | 2022-03-19 20:02:45 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2022-03-19 20:02:45 +0100 |
commit | c946ddda812c5c2d217061a9016eb8001970d659 (patch) | |
tree | eec7964b135a160244f5ef919f28658c4a988237 /lua/lvim/utils/git.lua | |
parent | 7192b28a24d52b62029c414db46b9fd3a5de475e (diff) |
feat: add alpha.nvim integration (#1906)
Diffstat (limited to 'lua/lvim/utils/git.lua')
-rw-r--r-- | lua/lvim/utils/git.lua | 53 |
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) |