Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BugFix: hook not executed when only config is updated #3

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 3 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
27 changes: 21 additions & 6 deletions dot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -370,11 +370,12 @@ end

local function handle_config_symlink(config, module_dir, options)
if not config.config then
return
return false
end

local configs = type(config.config) == "table" and config.config[1] and config.config or { config.config }
local all_configs_linked = true
local config_changed = false

for _, cfg in ipairs(configs) do
local source = os.getenv "PWD" .. "/" .. module_dir:gsub("^./", "") .. "/" .. cfg.source:gsub("^./", "")
Expand All @@ -387,6 +388,7 @@ local function handle_config_symlink(config, module_dir, options)
local success, err = delete_path(output)
if success then
print_message("success", "config → removed " .. output)
config_changed = true
else
print_message("error", "config → " .. err)
end
Expand All @@ -404,13 +406,14 @@ local function handle_config_symlink(config, module_dir, options)
local success, err = ensure_parent_directory(output)
if not success then
print_message("error", "config → " .. err)
return
return false
end

-- Copy source to output
local success, err = copy_path(source, output)
if success then
print_message("success", "config → copied " .. source .. " to " .. output)
config_changed = true
else
print_message("error", "config → " .. err)
end
Expand All @@ -433,19 +436,19 @@ local function handle_config_symlink(config, module_dir, options)
print_message("warning", "config → existing config backed up to " .. result)
else
print_message("error", "config → " .. result)
return
return false
end
else
print_message("error", "config → file already exists at " .. output .. ". Use -f to force.")
return
return false
end
end

-- Ensure parent directory exists
local success, err = ensure_parent_directory(output)
if not success then
print_message("error", "config → " .. err)
return
return false
end

local cmd = string.format('ln -sf "%s" "%s"', source, output)
Expand All @@ -454,6 +457,7 @@ local function handle_config_symlink(config, module_dir, options)
print_message("error", "config → failed to create symlink: " .. error_output)
else
print_message("success", "config → symlink created for " .. output)
config_changed = true
end
end
end
Expand All @@ -466,6 +470,8 @@ local function handle_config_symlink(config, module_dir, options)
elseif all_configs_linked and options.unlink_mode then
print_message("success", "all configurations are unlinked")
end

return config_changed
end

-- Process each module by installing/uninstalling dependencies and managing symlinks
Expand All @@ -490,7 +496,7 @@ local function process_module(module_name, options)

local dependencies_changed = process_brew_dependencies(config, options.purge_mode)

handle_config_symlink(config, module_dir, options)
local config_changed = handle_config_symlink(config, module_dir, options)

-- Run post_install or post_purge hooks
if dependencies_changed or options.hooks_mode then
Expand All @@ -501,6 +507,15 @@ local function process_module(module_name, options)
end
end

-- Run post_link or post_unlink hooks
if config_changed or options.hooks_mode then
if options.purge_mode and config.post_unlink then
run_hook(config.post_unlink, "post-unlink")
elseif not options.purge_mode and config.post_link then
run_hook(config.post_link, "post-link")
end
end

print "" -- Add a blank line between modules
end

Expand Down