浏览代码

Merge pull request #1921 from ferd/check-tool-avail

check if git/hg is installed
pull/1924/head
Fred Hebert 6 年前
提交者 GitHub
父节点
当前提交
78e0d7923d
找不到此签名对应的密钥 GPG 密钥 ID: 4AEE18F83AFDEB23
共有 2 个文件被更改,包括 38 次插入0 次删除
  1. +19
    -0
      src/rebar_git_resource.erl
  2. +19
    -0
      src/rebar_hg_resource.erl

+ 19
- 0
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.

+ 19
- 0
src/rebar_hg_resource.erl 查看文件

@ -18,6 +18,7 @@ init(Type, _State) ->
{ok, Resource}.
lock(AppInfo, _) ->
check_type_support(),
lock_(rebar_app_info:dir(AppInfo), rebar_app_info:source(AppInfo)).
lock_(AppDir, {hg, Url, _}) ->
@ -61,6 +62,7 @@ needs_update_(Dir, {hg, Url, Ref}) ->
not ((LocalRef =:= TargetRef) andalso compare_url(Dir, Url)).
download(TmpDir, AppInfo, State, _) ->
check_type_support(),
case download_(TmpDir, rebar_app_info:source(AppInfo), State) of
{ok, _} ->
ok;
@ -110,6 +112,7 @@ download_(Dir, {hg, Url, Rev}, _State) ->
[{cd, filename:dirname(Dir)}]).
make_vsn(AppInfo, _) ->
check_type_support(),
make_vsn_(rebar_app_info:dir(AppInfo)).
make_vsn_(Dir) ->
@ -183,3 +186,19 @@ parse_hg_url("http://" ++ HostPath) ->
parse_hg_url("https://" ++ HostPath) ->
[Host | Path] = rebar_string:lexemes(HostPath, "/"),
{Host, filename:rootname(filename:join(Path), ".hg")}.
check_type_support() ->
case get({is_supported, ?MODULE}) of
true ->
ok;
false ->
case rebar_utils:sh("hg --version", [{return_on_error, true},
{use_stdout, false}]) of
{error, _} ->
?ABORT("hg not installed", []);
_ ->
put({is_supported, ?MODULE}, true),
ok
end
end.

正在加载...
取消
保存