Skip to content

Commit

Permalink
git_resource: print warning from git rev-list, if any, in get_patch_c…
Browse files Browse the repository at this point in the history
…ount/2

In a situation after `git checkout -b <TAG>`, When
rebar_git_resource:get_patch_count/2 is called, the cloned repo is in
a state where it has a branch and a tag of the same name. This causes
`git rev-list <TAG>..HEAD` to print "warning: refname '<TAG>' is
ambiguous." to stdout, which in turn confuses the list_to_integer at
the end of that function and causes a badarg. Redirecting stderr to
/dev/null is sufficient to deal with this issue.

print the warning from git rev-list, if any
  • Loading branch information
Andrei Zavada committed Nov 30, 2021
1 parent 26d929b commit fafa86c
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/rebar_git_resource.erl
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,17 @@ get_patch_count(Dir, RawRef) ->
Ref = re:replace(RawRef, "\\s", "", [global, unicode]),
Cmd = io_lib:format("git rev-list --count ~ts..HEAD",
[rebar_utils:escape_chars(Ref)]),
{ok, PatchLines} = rebar_utils:sh(Cmd,
[{use_stdout, false},
{cd, Dir},
{debug_abort_on_error, AbortMsg}]),
{ok, list_to_integer(rebar_string:trim(PatchLines))}.
{ok, Output} = rebar_utils:sh(Cmd,
[{use_stdout, false},
{cd, Dir},
{debug_abort_on_error, AbortMsg}]),
case rebar_string:split(Output, "\n") of
[PatchLines] ->
{ok, list_to_integer(rebar_string:trim(PatchLines))};
[Warning, PatchLines] ->
?WARN("Extra message from git rev-list: ~ts", [Warning]),
{ok, list_to_integer(rebar_string:trim(PatchLines))}
end.


parse_tags(Dir) ->
Expand Down

0 comments on commit fafa86c

Please sign in to comment.