summaryrefslogtreecommitdiff
path: root/lua/lvim/utils
diff options
context:
space:
mode:
authorkylo252 <[email protected]>2022-03-24 15:48:33 +0100
committerkylo252 <[email protected]>2022-03-24 15:48:33 +0100
commitf41edc6dfb0d2a4c9875da08bbbdab121e52048f (patch)
treec6541278c6314e58d991bc95e547e903ac58340a /lua/lvim/utils
parent5ee460fdc751a91cdf7a4f4aab2ab784ebdb36fd (diff)
parent1ea836e3601b7ed0ed0496888dc14683bfbcce75 (diff)
Merge remote-tracking branch 'origin/rolling'1.1.3
Diffstat (limited to 'lua/lvim/utils')
-rw-r--r--lua/lvim/utils/git.lua53
-rw-r--r--lua/lvim/utils/hooks.lua6
2 files changed, 19 insertions, 40 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)
diff --git a/lua/lvim/utils/hooks.lua b/lua/lvim/utils/hooks.lua
index d28123ab..b40f2c23 100644
--- a/lua/lvim/utils/hooks.lua
+++ b/lua/lvim/utils/hooks.lua
@@ -12,8 +12,10 @@ function M.run_pre_reload()
end
function M.run_on_packer_complete()
- -- manually trigger event to fix colors
- vim.cmd [[ doautocmd ColorScheme ]]
+ if not in_headless then
+ -- manually trigger event to fix colors
+ vim.cmd [[ doautocmd ColorScheme ]]
+ end
Log:info "Reloaded configuration"
end