@@ -100,7 +100,10 @@ var isStable = function(version) {
100
100
* @return {Array.<SemVer> } The collection of previous versions
101
101
*/
102
102
var getPreviousVersions = function ( ) {
103
- var tagResults = shell . exec ( 'git tag' , { silent : true } ) ;
103
+ // always use the remote tags as the local clone might
104
+ // not contain all commits when cloned with git clone --depth=...
105
+ // Needed e.g. for Travis
106
+ var tagResults = shell . exec ( 'git ls-remote --tags | grep -o -e "v[0-9].*[0-9]$"' , { silent : true } ) ;
104
107
if ( tagResults . code === 0 ) {
105
108
return _ ( tagResults . output . trim ( ) . split ( '\n' ) )
106
109
. map ( function ( tag ) {
@@ -129,23 +132,34 @@ var getPreviousVersions = function() {
129
132
* @return {SemVer } The snapshot version
130
133
*/
131
134
var getSnapshotVersion = function ( ) {
132
-
133
135
version = _ ( previousVersions )
134
136
. filter ( function ( tag ) {
135
137
return semver . satisfies ( tag , currentPackage . branchVersion ) ;
136
138
} )
137
139
. last ( ) ;
138
140
139
141
if ( ! version ) {
140
- throw new Error ( "No valid versions can be found that match the current branch (" +
141
- currentPackage . branchVersion + ").\n" +
142
- "Try running `git fetch -t` to download the tags from the repository." ) ;
142
+ // a snapshot version before the first tag on the branch
143
+ version = semver ( currentPackage . branchVersion . replace ( '*' , '0-beta.1' ) ) ;
143
144
}
144
145
145
146
// We need to clone to ensure that we are not modifying another version
146
147
version = semver ( version . raw ) ;
147
148
148
149
var jenkinsBuild = process . env . TRAVIS_BUILD_NUMBER || process . env . BUILD_NUMBER ;
150
+ if ( ! version . prerelease || ! version . prerelease . length ) {
151
+ // last release was a non beta release. Increment the patch level to
152
+ // indicate the next release that we will be doing.
153
+ // E.g. last release was 1.3.0, then the snapshot will be
154
+ // 1.3.1-build.1, which is lesser than 1.3.1 accorind the semver!
155
+
156
+ // If the last release was a beta release we don't update the
157
+ // beta number by purpose, as otherwise the semver comparison
158
+ // does not work any more when the next beta is released.
159
+ // E.g. don't generate 1.3.0-beta.2.build.1
160
+ // as this is bigger than 1.3.0-beta.2 according to semver
161
+ version . patch ++ ;
162
+ }
149
163
version . prerelease = jenkinsBuild ? [ 'build' , jenkinsBuild ] : [ 'local' ] ;
150
164
version . build = getBuild ( ) ;
151
165
version . codeName = 'snapshot' ;
0 commit comments