Merge pull request #126 from tsloughter/git-vsn-fix

fix git command to find tags and default empty pattern
This commit is contained in:
Tristan Sloughter 2017-11-17 13:27:34 -08:00 committed by GitHub
commit a12eed3d1d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View file

@ -85,16 +85,20 @@ get_patch_count(RawRef) ->
os:cmd(Cmd).
-spec parse_tags(t()) -> {string()|undefined, ec_semver:version_string()}.
parse_tags({}) ->
parse_tags("");
parse_tags(Pattern) ->
Cmd = io_lib:format("git describe --abbrev=0 --match \"~s*\"", [Pattern]),
Cmd = io_lib:format("git describe --abbrev=0 --tags --match \"~s*\"", [Pattern]),
Tag = os:cmd(Cmd),
Vsn = slice(Tag, len(Pattern) + 1),
Vsn1 = trim(Vsn, left, "v"),
Vsn1 = trim(trim(Vsn, left, "v"), right, "\n"),
{Tag, Vsn1}.
-ifdef(unicode_str).
len(Str) -> string:length(Str).
trim(Str, Dir, Chars) -> string:trim(Str, Dir, Chars).
trim(Str, right, Chars) -> string:trim(Str, trailing, Chars);
trim(Str, left, Chars) -> string:trim(Str, leading, Chars);
trim(Str, both, Chars) -> string:trim(Str, both, Chars).
slice(Str, Len) -> string:slice(Str, Len).
-else.
len(Str) -> string:len(Str).

View file

@ -199,7 +199,9 @@ get_string(String) ->
-ifdef(unicode_str).
trim(Str) -> string:trim(Str).
trim(Str, Dir, Chars) -> string:trim(Str, Dir, Chars).
trim(Str, right, Chars) -> string:trim(Str, trailing, Chars);
trim(Str, left, Chars) -> string:trim(Str, leading, Chars);
trim(Str, both, Chars) -> string:trim(Str, both, Chars).
-else.
trim(Str) -> string:strip(Str).
trim(Str, Dir, [Chars|_]) -> string:strip(Str, Dir, Chars).