Skip to content

Commit

Permalink
Merge pull request #2663 from akontsevoy/git_default_branch
Browse files Browse the repository at this point in the history
Use default branch for git and git_subdir resources with no revision
  • Loading branch information
ferd authored Jan 4, 2022
2 parents d4f52f4 + 7e92826 commit c5176e3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion rebar.config.sample
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
{rebar, % mercurial is also supported
{hg, "https://github.com/rebar/rebar.git", {tag, "1.0.0"}}},
%% Alternative formats, backwards compatible declarations
{rebar, % implicit main, will warn recommending explicit branch
{rebar, % default branch, will warn recommending explicit branch
{git, "git://github.com/rebar/rebar.git"}},
{rebar, "1.0.*", % regex version check, ignored
{git, "git://github.com/rebar/rebar.git"}},
Expand Down
15 changes: 11 additions & 4 deletions src/rebar_git_resource.erl
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ needs_update_(Dir, {git, Url, "main"}) ->
needs_update_(Dir, {git, Url, {branch, "main"}});
needs_update_(Dir, {git, Url, "master"}) ->
needs_update_(Dir, {git, Url, {branch, "master"}});
needs_update_(Dir, {git, Url}) ->
{ok, _} = rebar_utils:sh("git fetch origin", [{cd, Dir}]),
{ok, Current} = rebar_utils:sh("git log HEAD..origin/HEAD --oneline",
[{cd, Dir}]),
?DEBUG("Checking new commits from HEAD to origin/HEAD: ~.7ts", [Current]),
not ((Current =:= []) andalso compare_url(Dir, Url));
needs_update_(Dir, {git, Url, ""}) ->
needs_update_(Dir, {git, Url});
needs_update_(Dir, {git, _, Ref}) ->
{ok, Current} = rebar_utils:sh(?FMT("git rev-parse --short=7 -q HEAD", []),
[{cd, Dir}]),
Expand Down Expand Up @@ -148,11 +156,10 @@ download(Dir, AppInfo, State) ->
download_(Dir, AppInfo, State).

download_(Dir, {git, Url}, State) ->
?WARN("WARNING: It is recommended to use {branch, Name}, {tag, Tag} or {ref, Ref}, otherwise updating the dep may not work as expected.", []),
download_(Dir, {git, Url, {branch, "master"}}, State);
?WARN("WARNING: It is recommended to use {branch, Name}, {tag, Tag} or {ref, Ref} since default branch selection is not consistent across all versions of rebar.", []),
download_(Dir, {git, Url, {ref, "origin/HEAD"}}, State);
download_(Dir, {git, Url, ""}, State) ->
?WARN("WARNING: It is recommended to use {branch, Name}, {tag, Tag} or {ref, Ref}, otherwise updating the dep may not work as expected.", []),
download_(Dir, {git, Url, {branch, "master"}}, State);
download_(Dir, {git, Url}, State);
download_(Dir, {git, Url, {branch, Branch}}, _State) ->
ok = filelib:ensure_dir(Dir),
maybe_warn_local_url(Url),
Expand Down

0 comments on commit c5176e3

Please sign in to comment.