forked from coop-cloud/tagcmp
Compare commits
1 Commits
05b56c0aad
...
721c863f44
Author | SHA1 | Date |
---|---|---|
knoflook | 721c863f44 |
18
tagcmp.go
18
tagcmp.go
|
@ -166,6 +166,24 @@ func (t Tag) IsCompatible(tag Tag) bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpgradeElement returns a Tag object which is the difference between an old and new tag
|
||||||
|
// It can contain negative numbers if comparing with an older tag.
|
||||||
|
func (curTag Tag) UpgradeElement(newTag Tag) (Tag, error) {
|
||||||
|
if !curTag.IsCompatible(newTag) {
|
||||||
|
return Tag{}, fmt.Errorf("%s and %s are not compatible with each other", curTag.String(), newTag.String())
|
||||||
|
}
|
||||||
|
diff := curTag
|
||||||
|
diff.Major(Itoa(Atoi(newTag.Major) - Atoi(curTag.Major)))
|
||||||
|
if !curTag.MissingMinor {
|
||||||
|
diff.Minor(Itoa(Atoi(newTag.Minor) - Atoi(curTag.Minor)))
|
||||||
|
}
|
||||||
|
if !curTag.MissingPatch {
|
||||||
|
diff.Patch(Itoa(Atoi(newTag.Patch) - Atoi(curTag.Patch)))
|
||||||
|
}
|
||||||
|
|
||||||
|
return diff, nil
|
||||||
|
}
|
||||||
|
|
||||||
// CommitHashPattern matches commit-like hash tags
|
// CommitHashPattern matches commit-like hash tags
|
||||||
var CommitHashPattern = "^[a-f0-9]{7,40}$"
|
var CommitHashPattern = "^[a-f0-9]{7,40}$"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue