Handle fallback version "0+unknown" correctly
This commit is contained in:
parent
aac661d292
commit
5579270108
@ -21,7 +21,7 @@ namespace gitversion {
|
|||||||
tie(result.majorVersion, result.minorVersion, result.versionTag) = _extractMajorMinorTag(versionNumber);
|
tie(result.majorVersion, result.minorVersion, result.versionTag) = _extractMajorMinorTag(versionNumber);
|
||||||
result.isDevVersion = (versionInfo != none);
|
result.isDevVersion = (versionInfo != none);
|
||||||
result.isStableVersion = !result.isDevVersion && (result.versionTag == "" || result.versionTag == "stable");
|
result.isStableVersion = !result.isDevVersion && (result.versionTag == "" || result.versionTag == "stable");
|
||||||
if (versionInfo != none) {
|
if (versionInfo != none && *versionInfo != "unknown") {
|
||||||
result.gitCommitId = _extractGitCommitId(*versionInfo);
|
result.gitCommitId = _extractGitCommitId(*versionInfo);
|
||||||
} else {
|
} else {
|
||||||
result.gitCommitId = "";
|
result.gitCommitId = "";
|
||||||
@ -47,20 +47,25 @@ namespace gitversion {
|
|||||||
};
|
};
|
||||||
|
|
||||||
tuple<string, string, string> Parser::_extractMajorMinorTag(const string &versionNumber) {
|
tuple<string, string, string> Parser::_extractMajorMinorTag(const string &versionNumber) {
|
||||||
regex splitRegex("^([0-9]+)\\.([0-9]+)\\.[0-9\\.]*(-(.*))?$");
|
regex splitRegex("^([0-9]+)(\\.([0-9]+))?(\\.[0-9\\.]*)?(-(.*))?$");
|
||||||
smatch match;
|
smatch match;
|
||||||
regex_match(versionNumber, match, splitRegex);
|
regex_match(versionNumber, match, splitRegex);
|
||||||
if(match[0] != versionNumber) {
|
if(match[0] != versionNumber) {
|
||||||
throw std::logic_error("First match group should be whole string");
|
throw std::logic_error("First match group should be whole string");
|
||||||
}
|
}
|
||||||
if(match.size() != 5) {
|
if(match.size() != 7) {
|
||||||
throw std::logic_error("Wrong number of match groups");
|
throw std::logic_error("Wrong number of match groups");
|
||||||
}
|
}
|
||||||
|
string major = match[1];
|
||||||
|
string minor = "0";
|
||||||
if (match[3].matched) {
|
if (match[3].matched) {
|
||||||
return std::make_tuple(match[1], match[2], match[4]);
|
minor = match[3];
|
||||||
} else {
|
|
||||||
return std::make_tuple(match[1], match[2], "");
|
|
||||||
}
|
}
|
||||||
|
string tag = "";
|
||||||
|
if (match[6].matched) {
|
||||||
|
tag = match[6];
|
||||||
|
}
|
||||||
|
return std::make_tuple(major, minor, tag);
|
||||||
};
|
};
|
||||||
|
|
||||||
string Parser::_extractGitCommitId(const string &versionInfo) {
|
string Parser::_extractGitCommitId(const string &versionInfo) {
|
||||||
|
@ -3,6 +3,16 @@
|
|||||||
|
|
||||||
using namespace gitversion;
|
using namespace gitversion;
|
||||||
|
|
||||||
|
TEST(ParserTest, TestUnknownVersion) {
|
||||||
|
VersionInfo info = Parser::parse("0+unknown");
|
||||||
|
EXPECT_EQ("0", info.majorVersion);
|
||||||
|
EXPECT_EQ("0", info.minorVersion);
|
||||||
|
EXPECT_TRUE( info.isDevVersion);
|
||||||
|
EXPECT_FALSE( info.isStableVersion);
|
||||||
|
EXPECT_EQ("", info.gitCommitId);
|
||||||
|
EXPECT_EQ("", info.versionTag);
|
||||||
|
}
|
||||||
|
|
||||||
TEST(ParserTest, TestReleaseVersion_1) {
|
TEST(ParserTest, TestReleaseVersion_1) {
|
||||||
VersionInfo info = Parser::parse("0.9.2");
|
VersionInfo info = Parser::parse("0.9.2");
|
||||||
EXPECT_EQ("0", info.majorVersion);
|
EXPECT_EQ("0", info.majorVersion);
|
||||||
@ -183,5 +193,3 @@ TEST(ParserTest, TestDirtyDevVersion_RCTag) {
|
|||||||
EXPECT_EQ("0123abcdef", info.gitCommitId);
|
EXPECT_EQ("0123abcdef", info.gitCommitId);
|
||||||
EXPECT_EQ("rc1", info.versionTag);
|
EXPECT_EQ("rc1", info.versionTag);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO Dirty non-dev version 0.7.0+0.g5753e4f.dirty
|
|
Loading…
Reference in New Issue
Block a user