|
|
@ -95,7 +95,9 @@ M.quit_doom = function(write, force) |
|
|
|
.. target_colorscheme |
|
|
|
.. '\'/" $HOME/.config/doom-nvim/doom_config.lua' |
|
|
|
) |
|
|
|
log.info('Colorscheme successfully changed to ' .. target_colorscheme) |
|
|
|
log.info( |
|
|
|
'Colorscheme successfully changed to ' .. target_colorscheme |
|
|
|
) |
|
|
|
end |
|
|
|
if target_background ~= config.doom.colorscheme_bg then |
|
|
|
vim.cmd( |
|
|
@ -107,7 +109,6 @@ M.quit_doom = function(write, force) |
|
|
|
) |
|
|
|
log.info('Background successfully changed to ' .. target_background) |
|
|
|
end |
|
|
|
|
|
|
|
end) |
|
|
|
|
|
|
|
if not changed_colorscheme then |
|
|
@ -187,4 +188,123 @@ M.create_report = function() |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
-- save_backup_hashes saves the commits or releases SHA for future rollbacks |
|
|
|
-- @tparam string git_workspace The git workspace to be used |
|
|
|
local function save_backup_hashes(git_workspace) |
|
|
|
-- Check for the current branch |
|
|
|
local branch_handler = io.popen(git_workspace .. 'branch ---show-current') |
|
|
|
local git_branch = branch_handler:read('a'):gsub('\n', '') |
|
|
|
branch_handler:close() |
|
|
|
|
|
|
|
if git_branch == 'main' then |
|
|
|
local releases_database_path = string.format( |
|
|
|
'%s/.doom_releases', |
|
|
|
utils.doom_root |
|
|
|
) |
|
|
|
|
|
|
|
-- Fetch for a file containing the releases tags |
|
|
|
log.info('Saving the Doom releases for future rollbacks ...') |
|
|
|
local saved_releases, releases_err = pcall(function() |
|
|
|
-- Get the releases |
|
|
|
local releases_handler = io.popen( |
|
|
|
git_workspace .. 'show-ref --tags' |
|
|
|
) |
|
|
|
local doom_releases = releases_handler:read('a') |
|
|
|
releases_handler:close() |
|
|
|
|
|
|
|
-- Put all the releases into a table so we can sort them later |
|
|
|
local releases = {} |
|
|
|
for release in doom_releases:gmatch('[^\r\n]+') do |
|
|
|
table.insert(releases, release) |
|
|
|
end |
|
|
|
-- Sort the releases table |
|
|
|
for idx, release in ipairs(releases) do |
|
|
|
releases[#releases + 1 - idx] = release |
|
|
|
end |
|
|
|
|
|
|
|
-- Check if the database already exists so we can check if the |
|
|
|
-- database is up-to-date or if we should override it. |
|
|
|
-- |
|
|
|
-- If the database does not exist yet then we will create it |
|
|
|
if vim.fn.filereadable(releases_database_path) == 1 then |
|
|
|
local current_releases = utils.read_file(releases_database_path) |
|
|
|
if current_releases ~= doom_releases then |
|
|
|
-- Write the first release in the list with 'w+' so the |
|
|
|
-- actual content will be overwritten by this one |
|
|
|
utils.write_file( |
|
|
|
releases_database_path, |
|
|
|
releases[1] .. '\n', |
|
|
|
'w+' |
|
|
|
) |
|
|
|
-- Write the rest of the releases |
|
|
|
for idx, release in ipairs(releases) do |
|
|
|
-- Exclude the first release because we have already |
|
|
|
-- written it in the database file |
|
|
|
if idx ~= 1 then |
|
|
|
utils.write_file( |
|
|
|
releases_database_path, |
|
|
|
release .. '\n', |
|
|
|
'a+' |
|
|
|
) |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
else |
|
|
|
for _, release in ipairs(releases) do |
|
|
|
utils.write_file( |
|
|
|
releases_database_path, |
|
|
|
release .. '\n', |
|
|
|
'a+' |
|
|
|
) |
|
|
|
end |
|
|
|
end |
|
|
|
end) |
|
|
|
|
|
|
|
if not saved_releases then |
|
|
|
log.error( |
|
|
|
'Error while saving the Doom releases. Traceback:\n' |
|
|
|
.. releases_err |
|
|
|
) |
|
|
|
end |
|
|
|
else |
|
|
|
-- Get the current commit SHA and store it into a hidden file |
|
|
|
log.info('Saving the current commit SHA for future rollbacks ...') |
|
|
|
local saved_backup_hash, backup_err = pcall(function() |
|
|
|
os.execute( |
|
|
|
git_workspace |
|
|
|
.. 'rev-parse --short HEAD > ' |
|
|
|
.. utils.doom_root |
|
|
|
.. '/.doom_backup_hash' |
|
|
|
) |
|
|
|
end) |
|
|
|
|
|
|
|
if not saved_backup_hash then |
|
|
|
log.error( |
|
|
|
'Error while saving the backup commit hash. Traceback:\n' |
|
|
|
.. backup_err |
|
|
|
) |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
-- update_doom saves the current commit/release hash into a file for future |
|
|
|
-- restore if needed and then updates Doom. |
|
|
|
M.update_doom = function() |
|
|
|
local git_workspace = string.format('git -C %s ', utils.doom_root) |
|
|
|
save_backup_hashes(git_workspace) |
|
|
|
|
|
|
|
log.info('Pulling Doom remote changes ...') |
|
|
|
local updated_doom, update_err = pcall(function() |
|
|
|
os.execute(git_workspace .. 'pull') |
|
|
|
end) |
|
|
|
|
|
|
|
if not updated_doom then |
|
|
|
log.error('Error while updating Doom. Traceback:\n' .. update_err) |
|
|
|
end |
|
|
|
-- Run syntax_on event to fix UI if it's broke after the git pull |
|
|
|
vim.cmd('syntax on') |
|
|
|
|
|
|
|
log.info('Successfully updated Doom, please restart') |
|
|
|
end |
|
|
|
|
|
|
|
return M |
|
|
|