From 381189c0064e8bb30ed77b3a464e12f147a58667 Mon Sep 17 00:00:00 2001 From: Joe DeVivo Date: Sun, 12 Jul 2015 07:31:08 -0700 Subject: [PATCH] Made grep version command's grep POSIX --- src/ec_git_vsn.erl | 5 ++++- test/ec_git_vsn_tests.erl | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test/ec_git_vsn_tests.erl diff --git a/src/ec_git_vsn.erl b/src/ec_git_vsn.erl index cc51a92..e832e84 100644 --- a/src/ec_git_vsn.erl +++ b/src/ec_git_vsn.erl @@ -86,7 +86,10 @@ get_patch_count(RawRef) -> -spec parse_tags(t()) -> {string()|undefined, ec_semver:version_string()}. parse_tags({Prefix}) -> - first_valid_tag(os:cmd("git log --oneline --decorate | fgrep \"tag: \" -1000"), Prefix). + first_valid_tag(os:cmd("git log --oneline --decorate | grep -F \"tag: \""), Prefix). + %% TODO: The following command sould be able to get the version + %% number directly, without a re:run. Should be checked for POSIX + %% "git log --oneline --decorate | grep -F \"tag: \" --color=never | head -n 1 | sed \"s/.*tag: " ++ Prefix ++ "\([^,)]*\).*/\1/\"". -spec first_valid_tag(string(), string()) -> {string()|undefined, ec_semver:version_string()}. first_valid_tag(Line, Prefix) -> diff --git a/test/ec_git_vsn_tests.erl b/test/ec_git_vsn_tests.erl new file mode 100644 index 0000000..b21abc1 --- /dev/null +++ b/test/ec_git_vsn_tests.erl @@ -0,0 +1,15 @@ +-module(ec_git_vsn_tests). +-include_lib("eunit/include/eunit.hrl"). +-compile([export_all]). + + +%% Hi! This test only works because you've cloned this repo out of git +%% AND we're tagging this repo with a "v" prefix. Hey, it's better +%% than nothing. +vsn_grep_test() -> + {ok, VSN} = ec_git_vsn:vsn({"v"}), + + [$v|OtherVSN] = os:cmd("git tag | xargs -I@ git log --format=format:\"%ai @%n\" -1 @ | sort -r | awk '{print $4}' | head -n 1"), + + ?assertEqual(OtherVSN, VSN ++ "\n"), + ok.