From 979610b44cba1feac72ce0954c66604b2f480808 Mon Sep 17 00:00:00 2001 From: Zachary Hueras Date: Wed, 16 Sep 2015 15:19:32 -0400 Subject: Make the v-prefix optional in git semver Not all repositories use a v-prefix for version tags. All tags should be considered valid versions. --- src/rebar_git_resource.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/rebar_git_resource.erl b/src/rebar_git_resource.erl index 2fc1ba9..5a24d1a 100644 --- a/src/rebar_git_resource.erl +++ b/src/rebar_git_resource.erl @@ -194,7 +194,7 @@ parse_tags(Dir) -> {error, _} -> {undefined, "0.0.0"}; {ok, Line} -> - case re:run(Line, "(\\(|\\s)tag:\\s(v([^,\\)]+))", [{capture, [2, 3], list}]) of + case re:run(Line, "(\\(|\\s)tag:\\s(v?([^,\\)]+))", [{capture, [2, 3], list}]) of {match,[Tag, Vsn]} -> {Tag, Vsn}; nomatch -> -- cgit v1.1 From 82faab2fe7683008a9a11a67abe49dd533916b47 Mon Sep 17 00:00:00 2001 From: Zachary Hueras Date: Wed, 16 Sep 2015 15:20:09 -0400 Subject: Only match current HEAD tag in git semver In the scenario that someone had cloned an entire repository and then checked out an older version tag, the semantic versioning would detect the newest tag, not the checked out tag. Look for the HEAD string prior to tag: to indicate the currently selected tag. --- src/rebar_git_resource.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/rebar_git_resource.erl b/src/rebar_git_resource.erl index 5a24d1a..0efdd1b 100644 --- a/src/rebar_git_resource.erl +++ b/src/rebar_git_resource.erl @@ -194,7 +194,7 @@ parse_tags(Dir) -> {error, _} -> {undefined, "0.0.0"}; {ok, Line} -> - case re:run(Line, "(\\(|\\s)tag:\\s(v?([^,\\)]+))", [{capture, [2, 3], list}]) of + case re:run(Line, "(\\(|\\s)(HEAD,\\s)tag:\\s(v?([^,\\)]+))", [{capture, [3, 4], list}]) of {match,[Tag, Vsn]} -> {Tag, Vsn}; nomatch -> -- cgit v1.1 From 1469e59c3afd437debf2f1649e03d814acf5eb1d Mon Sep 17 00:00:00 2001 From: Zachary Hueras Date: Wed, 16 Sep 2015 15:20:32 -0400 Subject: Improve semantic versioning from git between tags In the scenario we that we have selected a commit that is between two tags, we should base the version on the most recent tag we can see in the revision history, but we should not treat this as the tag version. `git describe --tags` finds the most recent tag visible in the revision history from the current HEAD. Return this as the version string and undefined as the tag to trigger ref counting. --- src/rebar_git_resource.erl | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/rebar_git_resource.erl b/src/rebar_git_resource.erl index 0efdd1b..6405e46 100644 --- a/src/rebar_git_resource.erl +++ b/src/rebar_git_resource.erl @@ -198,6 +198,12 @@ parse_tags(Dir) -> {match,[Tag, Vsn]} -> {Tag, Vsn}; nomatch -> - {undefined, "0.0.0"} + case rebar_utils:sh("git describe --tags", + [{use_stdout, false}, return_on_error, {cd, Dir}]) of + {error, _} -> + {undefined, "0.0.0"}; + {ok, LatestVsn} -> + {undefined, string:strip(LatestVsn, both, $\n)} + end end end. -- cgit v1.1