Skip to content

Commit aa77359

Browse files
committed
Avoid keyword pattern matching
When pattern matching using keywords the order matters and can cause problems.
1 parent 3b7cb27 commit aa77359

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

lib/config/branch_config.ex

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ defmodule GitHooks.Config.BranchConfig do
2626
@spec current_branch_allowed?(atom) :: boolean()
2727
def current_branch_allowed?(git_hook_type) do
2828
branch = current_branch()
29-
[whitelist: whitelist, blacklist: blacklist] = branches(git_hook_type)
29+
30+
branches_config = branches(git_hook_type)
31+
32+
whitelist = Keyword.get(branches_config, :whitelist, [])
33+
blacklist = Keyword.get(branches_config, :blacklist, [])
3034

3135
valid_branch?(branch, whitelist, blacklist)
3236
end
@@ -50,19 +54,15 @@ defmodule GitHooks.Config.BranchConfig do
5054
valid_branch?(branch, whitelist, []) or valid_branch?(branch, [], blacklist)
5155
end
5256

53-
@empty_branches [whitelist: [], blacklist: []]
5457
@spec branches() :: Keyword.t()
5558
defp branches do
56-
Keyword.merge(@empty_branches, Application.get_env(:git_hooks, :branches, []))
59+
Application.get_env(:git_hooks, :branches, [])
5760
end
5861

5962
@spec branches(atom) :: Keyword.t()
6063
defp branches(git_hook_type) do
61-
branches_config =
62-
git_hook_type
63-
|> Config.get_git_hook_type_config()
64-
|> Keyword.get_lazy(:branches, fn -> branches() end)
65-
66-
Keyword.merge(@empty_branches, branches_config)
64+
git_hook_type
65+
|> Config.get_git_hook_type_config()
66+
|> Keyword.get_lazy(:branches, fn -> branches() end)
6767
end
6868
end

0 commit comments

Comments
 (0)