Skip to content

Commit a4530c4

Browse files
committed
Refactor checking for Git sparse checkout support
1 parent 82a03f6 commit a4530c4

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

lib/mix/lib/mix/scm/git.ex

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ defmodule Mix.SCM.Git do
164164
defp sparse_toggle(opts) do
165165
cond do
166166
sparse = opts[:sparse] ->
167-
sparse_check(git_version())
167+
check_sparse_support(git_version())
168168
git!(["--git-dir=.git", "config", "core.sparsecheckout", "true"])
169169
File.mkdir_p!(".git/info")
170170
File.write!(".git/info/sparse-checkout", sparse)
@@ -180,13 +180,15 @@ defmodule Mix.SCM.Git do
180180
end
181181
end
182182

183-
defp sparse_check(version) do
184-
unless {1, 7, 4} <= version do
185-
version = version |> Tuple.to_list() |> Enum.join(".")
183+
defp check_sparse_support(version) do
184+
ensure_feature_compatibility(version, {1, 7, 4}, "sparse checkout")
185+
end
186186

187+
defp ensure_feature_compatibility(version, required_version, feature) do
188+
unless required_version <= version do
187189
Mix.raise(
188-
"Git >= 1.7.4 is required to use sparse checkout. " <>
189-
"You are running version #{version}"
190+
"Git >= #{format_version(required_version)} is required to use #{feature}. " <>
191+
"You are running version #{format_version(version)}"
190192
)
191193
end
192194
end
@@ -354,6 +356,10 @@ defmodule Mix.SCM.Git do
354356
|> List.to_tuple()
355357
end
356358

359+
defp format_version(version) do
360+
version |> Tuple.to_list() |> Enum.join(".")
361+
end
362+
357363
defp to_integer(string) do
358364
{int, _} = Integer.parse(string)
359365
int

0 commit comments

Comments
 (0)