From fafa86c5312aaae6d73a704738f9002b3b674918 Mon Sep 17 00:00:00 2001 From: Andrei Zavada Date: Mon, 29 Nov 2021 13:18:54 +0200 Subject: [PATCH] git_resource: print warning from git rev-list, if any, in get_patch_count/2 In a situation after `git checkout -b `, 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 ..HEAD` to print "warning: refname '' 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 --- src/rebar_git_resource.erl | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/rebar_git_resource.erl b/src/rebar_git_resource.erl index 52c6c85f5..898b9a09d 100644 --- a/src/rebar_git_resource.erl +++ b/src/rebar_git_resource.erl @@ -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) ->