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). os:cmd(Cmd).
-spec parse_tags(t()) -> {string()|undefined, ec_semver:version_string()}. -spec parse_tags(t()) -> {string()|undefined, ec_semver:version_string()}.
parse_tags({}) ->
parse_tags("");
parse_tags(Pattern) -> 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), Tag = os:cmd(Cmd),
Vsn = slice(Tag, len(Pattern) + 1), Vsn = slice(Tag, len(Pattern) + 1),
Vsn1 = trim(Vsn, left, "v"), Vsn1 = trim(trim(Vsn, left, "v"), right, "\n"),
{Tag, Vsn1}. {Tag, Vsn1}.
-ifdef(unicode_str). -ifdef(unicode_str).
len(Str) -> string:length(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). slice(Str, Len) -> string:slice(Str, Len).
-else. -else.
len(Str) -> string:len(Str). len(Str) -> string:len(Str).

View file

@ -199,7 +199,9 @@ get_string(String) ->
-ifdef(unicode_str). -ifdef(unicode_str).
trim(Str) -> string:trim(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. -else.
trim(Str) -> string:strip(Str). trim(Str) -> string:strip(Str).
trim(Str, Dir, [Chars|_]) -> string:strip(Str, Dir, Chars). trim(Str, Dir, [Chars|_]) -> string:strip(Str, Dir, Chars).