Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ysbaddaden/5ac019b3627b7c383545d49a15f1895b to your computer and use it in GitHub Desktop.
Save ysbaddaden/5ac019b3627b7c383545d49a15f1895b to your computer and use it in GitHub Desktop.
Fix for Rebar2 that transparently rewrites git://github.com into https://github.com (useful to bootstrap old legacy Erlang projects)
commit 921120d96c175d997d815805bdeced4b4fbb0cfa (HEAD -> fix/transparently-rewrite-unauthenticated-github-url-to-https)
Author: Julien Portalier <[email protected]>
Date: Tue Apr 5 18:37:34 2022 +0200
Fix: rewrite GitHub unauthenticated URL
Rewrites the URL on-the-fly and transparently from git://github.com
to https://github.com because GitHub no longer supports the
unauthenticated git protocol anymore.
diff --git a/src/rebar_config.erl b/src/rebar_config.erl
index a46c964..be04655 100644
--- a/src/rebar_config.erl
+++ b/src/rebar_config.erl
@@ -112,9 +112,30 @@ get_list(Config, Key, Default) ->
get(Config, Key, Default).
-spec get_local(config(), key(), term()) -> term().
+get_local(Config, deps, Default) ->
+ Deps = proplists:get_value(deps, local_opts(Config#config.opts, []), Default),
+ lists:map(fun rewrite_dep/1, Deps);
get_local(Config, Key, Default) ->
proplists:get_value(Key, local_opts(Config#config.opts, []), Default).
+rewrite_dep({Name, Version, Source}) ->
+ {Name, Version, rewrite_dep_source(Source)}.
+
+rewrite_dep_source({git, Url, Options}) ->
+ {git, rewrite_github_url(Url), Options};
+rewrite_dep_source({git, Url}) ->
+ {git, rewrite_github_url(Url)};
+rewrite_dep_source(Dep) ->
+ Dep.
+
+rewrite_github_url(Url) ->
+ case string:str(Url, "git://github.com/") of
+ 1 ->
+ "https://github.com/" ++ string:substr(Url, 18);
+ _ ->
+ Url
+ end.
+
-spec get_all(config(), key()) -> list(term()).
get_all(Config, Key) ->
proplists:get_all_values(Key, Config#config.opts).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment