summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rebar_git_resource.erl53
-rw-r--r--test/rebar_as_SUITE.erl34
2 files changed, 62 insertions, 25 deletions
diff --git a/src/rebar_git_resource.erl b/src/rebar_git_resource.erl
index 97e951e..bea74a2 100644
--- a/src/rebar_git_resource.erl
+++ b/src/rebar_git_resource.erl
@@ -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
diff --git a/test/rebar_as_SUITE.erl b/test/rebar_as_SUITE.erl
index 1d1112b..99c7e30 100644
--- a/test/rebar_as_SUITE.erl
+++ b/test/rebar_as_SUITE.erl
@@ -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).