summaryrefslogtreecommitdiff
path: root/src/rebar_git_resource.erl
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2018-10-20 16:14:03 -0400
committerFred Hebert <mononcqc@ferd.ca>2018-10-20 16:32:34 -0400
commita279020d1b860313719a3ba07972004b8235146d (patch)
treeb17c5fa70874649cf2b5e0872fe89e6f94a8ebfc /src/rebar_git_resource.erl
parentac69c3898609c5ff55c063c6ac12c6c201ab0cc0 (diff)
check if git/hg is installed
This PR is a simpler and mergeable version of #1853 by @shamis, since the provider changed format enough to make merging difficult. Compared to #1853, this also puts the responsibility on each resource to check rather than adding a new optional callback. The process dictionary is use as a warning/check cache.
Diffstat (limited to 'src/rebar_git_resource.erl')
-rw-r--r--src/rebar_git_resource.erl19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/rebar_git_resource.erl b/src/rebar_git_resource.erl
index 29c9ad7..03aa6d8 100644
--- a/src/rebar_git_resource.erl
+++ b/src/rebar_git_resource.erl
@@ -21,6 +21,7 @@ init(Type, _State) ->
{ok, Resource}.
lock(AppInfo, _) ->
+ check_type_support(),
lock_(rebar_app_info:dir(AppInfo), rebar_app_info:source(AppInfo)).
lock_(AppDir, {git, Url, _}) ->
@@ -43,6 +44,7 @@ lock_(AppDir, {git, Url}) ->
%% Return true if either the git url or tag/branch/ref is not the same as the currently
%% checked out git repo for the dep
needs_update(AppInfo, _) ->
+ check_type_support(),
needs_update_(rebar_app_info:dir(AppInfo), rebar_app_info:source(AppInfo)).
needs_update_(Dir, {git, Url, {tag, Tag}}) ->
@@ -111,6 +113,7 @@ parse_git_url(not_scp, Url) ->
end.
download(TmpDir, AppInfo, State, _) ->
+ check_type_support(),
case download_(TmpDir, rebar_app_info:source(AppInfo), State) of
{ok, _} ->
ok;
@@ -307,3 +310,19 @@ parse_tags(Dir) ->
end
end
end.
+
+check_type_support() ->
+ case get({is_supported, ?MODULE}) of
+ true ->
+ ok;
+ _ ->
+ case rebar_utils:sh("git --version", [{return_on_error, true},
+ {use_stdout, false}]) of
+ {error, _} ->
+ ?ABORT("git not installed", []);
+ _ ->
+ put({is_supported, ?MODULE}, true),
+ ok
+ end
+ end.
+