@@ -70,15 +70,18 @@ module GitVersion
70
70
return (exec cmd)[0 ].rjust(7 , '0' )
71
71
end
72
72
73
- def commits_distance (latest_tagged_version )
74
- return (exec " git rev-list --count HEAD ^#{ latest_tagged_version } " )[0 ]
73
+ def commits_distance (tag : String | Nil )
74
+ if tag.nil?
75
+ return (exec " git rev-list --count HEAD" )[0 ]
76
+ else
77
+ return (exec " git rev-list --count HEAD ^#{ tag } " )[0 ]
78
+ end
75
79
rescue
76
80
return 0
77
81
end
78
82
79
- def get_bumps (latest )
80
- latest_exists = (exec " git tag -l #{ latest } " )
81
- if latest_exists.any?
83
+ def get_bumps (latest : String | Nil )
84
+ if ! latest.nil? && (exec " git tag -l #{ latest } " ).any?
82
85
last_commit = (exec " git show-ref -s #{ latest } " )[0 ]
83
86
return (exec " git log --pretty=%B #{ last_commit } ..HEAD #{ log_paths_filter } " )
84
87
else
@@ -94,26 +97,26 @@ module GitVersion
94
97
branch_tags = tags_by_branch(cb)
95
98
96
99
latest_version = BASE_VERSION
100
+ latest_tag = nil
97
101
98
102
branch_tags.each do |tag |
99
103
begin
100
104
tag_without_prefix = strip_prefix(tag)
101
105
if tag_without_prefix.nil?
102
106
next
103
107
end
104
- current_tag = SemanticVersion .parse(tag_without_prefix)
105
- if ! current_tag .prerelease.identifiers.empty?
108
+ current_version = SemanticVersion .parse(tag_without_prefix)
109
+ if ! current_version .prerelease.identifiers.empty?
106
110
next
107
- elsif (latest_version < current_tag)
108
- latest_version = current_tag
111
+ elsif (latest_version < current_version)
112
+ latest_version = current_version
113
+ latest_tag = tag
109
114
end
110
115
rescue
111
116
#
112
117
end
113
118
end
114
119
115
- latest_tagged_version = latest_version
116
-
117
120
latest_version =
118
121
SemanticVersion .new(
119
122
latest_version.major,
@@ -124,7 +127,7 @@ module GitVersion
124
127
)
125
128
126
129
major = false
127
- get_bumps(latest_tagged_version ).each do |bump |
130
+ get_bumps(latest_tag ).each do |bump |
128
131
commit = bump.downcase
129
132
if commit.includes?(MAJOR_BUMP_COMMENT )
130
133
latest_version =
@@ -141,7 +144,7 @@ module GitVersion
141
144
end
142
145
143
146
if ! major
144
- get_bumps(latest_tagged_version ).each do |bump |
147
+ get_bumps(latest_tag ).each do |bump |
145
148
commit = bump.downcase
146
149
if commit.includes?(MINOR_BUMP_COMMENT )
147
150
latest_version =
@@ -160,7 +163,7 @@ module GitVersion
160
163
if cb == @release_branch
161
164
#
162
165
elsif cb == @dev_branch
163
- prerelease = [DEV_BRANCH_SUFFIX , commits_distance(latest_tagged_version ), current_commit_hash()] of String | Int32
166
+ prerelease = [DEV_BRANCH_SUFFIX , commits_distance(latest_tag ), current_commit_hash()] of String | Int32
164
167
latest_version =
165
168
SemanticVersion .new(
166
169
latest_version.major,
@@ -171,7 +174,7 @@ module GitVersion
171
174
)
172
175
else
173
176
branch_sanitized_name = cb.downcase.gsub(/[^a-zA-Z0-9] / , " " )
174
- prerelease = [branch_sanitized_name, commits_distance(latest_tagged_version ), current_commit_hash()] of String | Int32
177
+ prerelease = [branch_sanitized_name, commits_distance(latest_tag ), current_commit_hash()] of String | Int32
175
178
latest_version =
176
179
SemanticVersion .new(
177
180
latest_version.major,
0 commit comments