diff options
author | iw <none@none> | 2010-01-06 22:22:05 +0000 |
---|---|---|
committer | iw <none@none> | 2010-01-06 22:22:05 +0000 |
commit | 864d4b74d6591737f6eb05e937db1d1237757af1 (patch) | |
tree | 80a52e8db6cd84e56ac05e9ad8447503e91d002b | |
parent | 59b1f74498ecb6f696a1d6adec5771237b2246cc (diff) |
Ensure we have the correct hg version
-rw-r--r-- | src/rebar_deps.erl | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/src/rebar_deps.erl b/src/rebar_deps.erl index 530dcd7..5f94323 100644 --- a/src/rebar_deps.erl +++ b/src/rebar_deps.erl @@ -31,6 +31,8 @@ -export([preprocess/2, distclean/2]). +-define(HG_VERSION, "1.4"). + %% =================================================================== %% Public API %% =================================================================== @@ -207,13 +209,31 @@ download_source(AppDir, {hg, Url, Rev}) -> %% =================================================================== source_engine_avail({hg, _, _}) -> - Res = os:cmd("which hg"), - ?DEBUG("which hg = ~p\n", [Res]), - case Res of - [] -> + Path = os:find_executable("hg"), + ?DEBUG("which hg = ~p\n", [Path]), + case Path of + false -> false; _ -> - true + ensure_required_scm_client(hg, Path) end; source_engine_avail(_) -> false. + +%% We expect the initial part of the version string to be of the form: +%% "Mercurial Distributed SCM (version 1.4.1+20091201)". Rebar +%% requires version 1.4 or higher. +ensure_required_scm_client(hg, Path) -> + Info = os:cmd(Path ++ " --version"), + case re:run(Info, "version (\\d*\.\\d*\.\\d*)", [{capture, all_but_first, list}]) of + {match, [Vsn]} -> + case Vsn >= ?HG_VERSION of + true -> + true; + false -> + ?ABORT("Rebar requires version ~p or higher of hg (~p)~n", + [?HG_VERSION, Path]) + end; + _ -> + false + end. |