From 392108000a70deb0dc284e419ff4f6dadd7bcc0b Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Tue, 3 Mar 2015 09:01:04 -0600 Subject: use rebar_utils:sh for git and hg commands to have better errors and logs --- src/rebar_hg_resource.erl | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'src/rebar_hg_resource.erl') diff --git a/src/rebar_hg_resource.erl b/src/rebar_hg_resource.erl index a0ebb6d..1bd992e 100644 --- a/src/rebar_hg_resource.erl +++ b/src/rebar_hg_resource.erl @@ -80,7 +80,12 @@ make_vsn(Dir) -> Ref = get_ref(Dir), Cmd = BaseHg ++ "log --template \"{latesttag}+build.{latesttagdistance}.rev.{node|short}\"" " --rev " ++ Ref, - RawVsn = string:strip(os:cmd(Cmd), both, $\n), + AbortMsg = io_lib:format("Version resolution of hg dependency failed in ~s", [Dir]), + {ok, VsnString} = + rebar_utils:sh(Cmd, + [{use_stdout, false}, {debug_abort_on_error, AbortMsg}]), + RawVsn = string:strip(VsnString, both, $\n), + Vsn = case RawVsn of "null+" ++ Rest -> "0.0.0+" ++ Rest; _ -> RawVsn @@ -95,20 +100,30 @@ compare_url(Dir, Url) -> parse_hg_url(CurrentUrl1) =:= parse_hg_url(Url). get_ref(Dir) -> - string:strip(os:cmd("hg -R '" ++ Dir ++ "' --debug id -i"), both, $\n). + AbortMsg = io_lib:format("Get ref of hg dependency failed in ~s", [Dir]), + {ok, RefString} = + rebar_utils:sh("hg -R '" ++ Dir ++ "' --debug id -i", + [{use_stdout, false}, {debug_abort_on_error, AbortMsg}]), + string:strip(RefString, both, $\n). get_tag_distance(Dir, Ref) -> - Log = string:strip(os:cmd("hg -R '" ++ Dir ++ "' " - "log --template \"{latesttag}-{latesttagdistance}\n\" " - "--rev " ++ Ref), + AbortMsg = io_lib:format("Get tag distance of hg dependency failed in ~s", [Dir]), + {ok, LogString} = + rebar_utils:sh("hg -R '" ++ Dir ++ "' " + "log --template \"{latesttag}-{latesttagdistance}\n\" " + "--rev " ++ Ref, + [{use_stdout, false}, {debug_abort_on_error, AbortMsg}]), + Log = string:strip(LogString, both, $\n), [Tag, Distance] = re:split(Log, "-([0-9]+)$", [{parts,0}]), {Tag, Distance}. get_branch_ref(Dir, Branch) -> - string:strip( - os:cmd("hg -R '" ++ Dir ++ "' log --template \"{node}\n\" --rev " ++ Branch), - both, $\n). + AbortMsg = io_lib:format("Get branch ref of hg dependency failed in ~s", [Dir]), + {ok, BranchRefString} = + rebar_utils:sh("hg -R '" ++ Dir ++ "' log --template \"{node}\n\" --rev " ++ Branch, + [{use_stdout, false}, {debug_abort_on_error, AbortMsg}]), + string:strip(BranchRefString, both, $\n). parse_hg_url("ssh://" ++ HostPath) -> [Host | Path] = string:tokens(HostPath, "/"), -- cgit v1.1