diff options
author | Fred Hebert <mononcqc@ferd.ca> | 2019-05-12 19:17:22 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-12 19:17:22 -0400 |
commit | 3a16cf3763c198e9167ec11a146e25334adc82f5 (patch) | |
tree | 034492a364d91c64b142f2d2d7ecf56801fdb83a /src/rebar_git_resource.erl | |
parent | cbe3292b52802a8ef7b39a40287d1cd8019f46a1 (diff) | |
parent | 67026e08916578a03ae5637284ad5eb6818a3c7f (diff) |
Merge pull request #2074 from tsloughter/git-ref
add support for git ref and file content as app version
Diffstat (limited to 'src/rebar_git_resource.erl')
-rw-r--r-- | src/rebar_git_resource.erl | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/rebar_git_resource.erl b/src/rebar_git_resource.erl index ac1316b..4e81c05 100644 --- a/src/rebar_git_resource.erl +++ b/src/rebar_git_resource.erl @@ -236,7 +236,17 @@ git_vsn_fetch() -> end. make_vsn(AppInfo, _) -> - make_vsn_(rebar_app_info:dir(AppInfo)). + Dir = rebar_app_info:dir(AppInfo), + case rebar_app_info:original_vsn(AppInfo) of + {git, short} -> + git_ref(Dir, "--short"); + {git, long} -> + git_ref(Dir, ""); + _ -> + %% already parsed in rebar_utils to get here so we know it + %% is either for git or "git" + make_vsn_(Dir) + end. make_vsn_(Dir) -> case collect_default_refcount(Dir) of @@ -248,6 +258,19 @@ make_vsn_(Dir) -> %% Internal functions +git_ref(Dir, Arg) -> + case rebar_utils:sh("git rev-parse " ++ Arg ++ " HEAD", + [{use_stdout, false}, + return_on_error, + {cd, Dir}]) of + {error, _} -> + ?WARN("Getting ref of git repo failed in ~ts. " + "Falling back to version 0", [Dir]), + {plain, "0"}; + {ok, String} -> + {plain, rebar_string:trim(String, both, "\n")} + end. + collect_default_refcount(Dir) -> %% Get the tag timestamp and minimal ref from the system. The %% timestamp is really important from an ordering perspective. @@ -256,7 +279,8 @@ collect_default_refcount(Dir) -> return_on_error, {cd, Dir}]) of {error, _} -> - ?WARN("Getting log of git dependency failed in ~ts. Falling back to version 0.0.0", [rebar_dir:get_cwd()]), + ?WARN("Getting log of git repo failed in ~ts. " + "Falling back to version 0.0.0", [Dir]), {plain, "0.0.0"}; {ok, String} -> RawRef = rebar_string:trim(String, both, "\n"), |