Procházet zdrojové kódy

Merge pull request #5 from ferd/tsloughter-no_profile

Tsloughter no profile
pull/852/head
Tristan Sloughter před 9 roky
rodič
revize
ea56749f73
2 změnil soubory, kde provedl 62 přidání a 25 odebrání
  1. +30
    -23
      src/rebar_git_resource.erl
  2. +32
    -2
      test/rebar_as_SUITE.erl

+ 30
- 23
src/rebar_git_resource.erl Zobrazit soubor

@ -130,36 +130,43 @@ download(Dir, {git, Url, Rev}, _State) ->
[{cd, Dir}]).
make_vsn(Dir) ->
{Vsn, RawRef, RawCount} = collect_default_refcount(Dir),
{plain, build_vsn_string(Vsn, RawRef, RawCount)}.
case collect_default_refcount(Dir) of
Vsn={plain, _} ->
Vsn;
{Vsn, RawRef, RawCount} ->
{plain, build_vsn_string(Vsn, RawRef, RawCount)}
end.
%% Internal functions
collect_default_refcount(Dir) ->
%% Get the tag timestamp and minimal ref from the system. The
%% timestamp is really important from an ordering perspective.
AbortMsg1 = "Getting log of git dependency failed in " ++ rebar_dir:get_cwd(),
{ok, String} =
rebar_utils:sh("git log -n 1 --pretty=format:\"%h\n\" ",
case rebar_utils:sh("git log -n 1 --pretty=format:\"%h\n\" ",
[{use_stdout, false},
{cd, Dir},
{debug_abort_on_error, AbortMsg1}]),
RawRef = string:strip(String, both, $\n),
{Tag, TagVsn} = parse_tags(Dir),
{ok, RawCount} =
case Tag of
undefined ->
AbortMsg2 = "Getting rev-list of git depedency failed in " ++ Dir,
{ok, PatchLines} = rebar_utils:sh("git rev-list HEAD",
[{use_stdout, false},
{cd, Dir},
{debug_abort_on_error, AbortMsg2}]),
rebar_utils:line_count(PatchLines);
_ ->
get_patch_count(Dir, Tag)
end,
{TagVsn, RawRef, RawCount}.
return_on_error,
{cd, Dir}]) of
{error, _} ->
?WARN("Getting log of git dependency failed in ~s. Falling back to version 0.0.0", [rebar_dir:get_cwd()]),
{plain, "0.0.0"};
{ok, String} ->
RawRef = string:strip(String, both, $\n),
{Tag, TagVsn} = parse_tags(Dir),
{ok, RawCount} =
case Tag of
undefined ->
AbortMsg2 = "Getting rev-list of git depedency failed in " ++ Dir,
{ok, PatchLines} = rebar_utils:sh("git rev-list HEAD",
[{use_stdout, false},
{cd, Dir},
{debug_abort_on_error, AbortMsg2}]),
rebar_utils:line_count(PatchLines);
_ ->
get_patch_count(Dir, Tag)
end,
{TagVsn, RawRef, RawCount}
end.
build_vsn_string(Vsn, RawRef, Count) ->
%% Cleanup the tag and the Ref information. Basically leading 'v's and

+ 32
- 2
test/rebar_as_SUITE.erl Zobrazit soubor

@ -12,7 +12,8 @@
as_comma_placement/1,
as_comma_then_space/1,
as_dir_name/1,
as_with_task_args/1]).
as_with_task_args/1,
warn_on_empty_profile/1]).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
@ -30,7 +31,8 @@ init_per_testcase(_, Config) ->
all() -> [as_basic, as_multiple_profiles, as_multiple_tasks,
as_multiple_profiles_multiple_tasks,
as_comma_placement, as_comma_then_space,
as_dir_name, as_with_task_args].
as_dir_name, as_with_task_args,
warn_on_empty_profile].
as_basic(Config) ->
AppDir = ?config(apps, Config),
@ -136,3 +138,31 @@ as_with_task_args(Config) ->
[],
["as", "default", "clean", "-a"],
{ok, [{app, Name, invalid}]}).
warn_on_empty_profile(Config) ->
AppDir = ?config(apps, Config),
Name = rebar_test_utils:create_random_name("as_warn_empty_"),
Vsn = rebar_test_utils:create_random_vsn(),
rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
meck:new(rebar_log, [passthrough]),
rebar_test_utils:run_and_check(Config,
[],
["as", "fake1,fake2", "compile"],
{ok, [{app, Name}]}),
History = meck:history(rebar_log),
?assert(warn_match("fake1", History)),
?assert(warn_match("fake2", History)),
meck:unload(rebar_log),
ok.
warn_match(App, History) ->
lists:any(
fun({_, {rebar_log,log, [warn, "No entry for profile ~s in config.",
[ArgApp]]}, _}) -> ArgApp =:= App
; (_) ->
false
end,
History).

Načítá se…
Zrušit
Uložit