Fix VersionCompare for stable versions vs tag versions
This commit is contained in:
parent
03f59b69da
commit
4069358b31
@ -16,7 +16,7 @@ namespace gitversion {
|
||||
unsigned long v2_minor = std::stoul(v2.minorVersion);
|
||||
unsigned long v1_hotfix = std::stoul(v1.hotfixVersion);
|
||||
unsigned long v2_hotfix = std::stoul(v2.hotfixVersion);
|
||||
int versionTagCompare = strcmp(v1.versionTag.c_str(), v2.versionTag.c_str());
|
||||
int versionTagCompare = _versionTagCompare(v1.versionTag, v2.versionTag);
|
||||
return (v1_major < v2_major) || ((v1_major == v2_major) && (
|
||||
(v1_minor < v2_minor) || ((v1_minor == v2_minor) && (
|
||||
(v1_hotfix < v2_hotfix) || ((v1_hotfix == v2_hotfix) && (
|
||||
@ -24,4 +24,20 @@ namespace gitversion {
|
||||
(v1.commitsSinceTag < v2.commitsSinceTag)
|
||||
))))))));
|
||||
}
|
||||
|
||||
int VersionCompare::_versionTagCompare(const string &tag1, const string &tag2) {
|
||||
if (tag1 == "") {
|
||||
if (tag2 == "") {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
if (tag2 == "") {
|
||||
return -1;
|
||||
} else {
|
||||
return strcmp(tag1.c_str(), tag2.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,9 @@ namespace gitversion {
|
||||
class VersionCompare {
|
||||
public:
|
||||
static bool isOlderThan(const std::string &v1, const std::string &v2);
|
||||
|
||||
private:
|
||||
static int _versionTagCompare(const std::string &tag1, const std::string &tag2);
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,8 @@ TEST_F(VersionCompareTest, VersionTags) {
|
||||
EXPECT_IS_OLDER_THAN("0.9.3-alpha", "0.9.3-beta");
|
||||
EXPECT_IS_OLDER_THAN("1.0-beta", "1.0-rc1");
|
||||
EXPECT_IS_OLDER_THAN("1.0-rc1", "1.0-rc2");
|
||||
EXPECT_IS_OLDER_THAN("1.0-rc2", "1.0-stable");
|
||||
EXPECT_IS_OLDER_THAN("1.0-rc2", "1.0");
|
||||
EXPECT_IS_OLDER_THAN("1.0-alpha", "1.0");
|
||||
EXPECT_IS_SAME_AGE("0.9.3-alpha", "0.9.3-alpha");
|
||||
EXPECT_IS_SAME_AGE("1-beta", "1-beta");
|
||||
EXPECT_IS_SAME_AGE("0.9.3-rc1", "0.9.3-rc1");
|
||||
|
Loading…
x
Reference in New Issue
Block a user