diff options
author | Fred Hebert <mononcqc@ferd.ca> | 2015-10-04 13:32:14 -0400 |
---|---|---|
committer | Fred Hebert <mononcqc@ferd.ca> | 2015-10-04 13:32:14 -0400 |
commit | 2b228fafce32b7b523c1649d86926ae18ceb1346 (patch) | |
tree | e97be4ebbfdabdcaf9e5134a5b2fbecb7dde6b14 /src | |
parent | 4177c75a7c709b615962b1a885c119a51ed0aab0 (diff) | |
parent | 1337de64544b88a2c91fdcd020ee87122418b3a1 (diff) |
Merge pull request #854 from tsloughter/git_vsn
if not in a git repo but have 'git' as vsn, fallback to 0.0.0
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar_git_resource.erl | 53 |
1 files changed, 30 insertions, 23 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 |