diff options
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"), |