diff options
author | Fred Hebert <mononcqc@ferd.ca> | 2015-03-03 10:24:01 -0500 |
---|---|---|
committer | Fred Hebert <mononcqc@ferd.ca> | 2015-03-03 10:24:01 -0500 |
commit | 27dae6a65570811a0e15d12559cc9220784995a4 (patch) | |
tree | 1ae17b5882431be201d9624d520c853a8e4b5b3a /src/rebar_hg_resource.erl | |
parent | 46bd6fc59dd71065ce1986afb3b6a813739ba39d (diff) | |
parent | 392108000a70deb0dc284e419ff4f6dadd7bcc0b (diff) |
Merge pull request #204 from tsloughter/git_hg_cmd
use rebar_utils:sh for git and hg commands to have better errors and log
Diffstat (limited to 'src/rebar_hg_resource.erl')
-rw-r--r-- | src/rebar_hg_resource.erl | 31 |
1 files changed, 23 insertions, 8 deletions
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, "/"), |