17
17
import java .util .regex .Pattern ;
18
18
19
19
import static org .assertj .core .api .Assertions .assertThat ;
20
- import static org .assertj .core .api .SoftAssertions .assertSoftly ;
21
20
import static org .eclipse .jgit .lib .Constants .HEAD ;
22
21
import static org .eclipse .jgit .lib .Constants .MASTER ;
23
22
@@ -189,7 +188,7 @@ void describe() throws Exception {
189
188
git .tag ().setName (givenTagName ).setAnnotated (true ).setObjectId (givenCommit ).setMessage ("." ).call ();
190
189
191
190
// when
192
- GitDescription description = GitUtil .describe (head (git ), Pattern .compile ("v.+" ), git .getRepository (), true );
191
+ GitDescription description = GitUtil .describe (head (git ), Pattern .compile ("v.+" ), git .getRepository (), true , - 1 );
193
192
194
193
// then
195
194
assertThat (description ).satisfies (it -> {
@@ -207,11 +206,31 @@ void distanceOrZeroIsZeroWhenNoTagMatches() throws Exception {
207
206
208
207
final var softly = new SoftAssertions ();
209
208
for (int i = 0 ; i < 3 ; ++i ) {
210
- GitDescription description = GitUtil .describe (head (git ), Pattern .compile ("v.+" ), git .getRepository (), true );
209
+ GitDescription description = GitUtil .describe (head (git ), Pattern .compile ("v.+" ), git .getRepository (), true , -1 );
210
+ softly .assertThat (description .isTagFound ()).isFalse ();
211
211
softly .assertThat (description .getDistanceOrZero ()).isZero ();
212
212
softly .assertThat (description .getDistance ()).isEqualTo (i );
213
213
git .commit ().setMessage ("commit " + (i + 1 )).setAllowEmpty (true ).call ();
214
214
}
215
215
softly .assertAll ();
216
216
}
217
+
218
+ @ Test
219
+ void distanceWithMaxDepth () throws Exception {
220
+ // given
221
+ final int maxDepth = 4 ;
222
+ Git git = Git .init ().setInitialBranch (MASTER ).setDirectory (tempDir .toFile ()).call ();
223
+ final RevCommit firstCommit = git .commit ().setMessage ("initial commit" ).setAllowEmpty (true ).call ();
224
+ git .tag ().setName ("v1.0.0" ).setAnnotated (true ).setObjectId (firstCommit ).setMessage ("." ).call ();
225
+
226
+ final SoftAssertions softly = new SoftAssertions ();
227
+ for (int i = 0 ; i < 6 ; ++i ) {
228
+ GitDescription description = GitUtil .describe (head (git ), Pattern .compile ("v.+" ), git .getRepository (), true , maxDepth );
229
+ softly .assertThat (description .isTagFound ()).as ("distanceOrZero " + i ).isEqualTo (i < maxDepth );
230
+ softly .assertThat (description .getDistanceOrZero ()).as ("distanceOrZero " + i ).isEqualTo (i >= maxDepth ? 0 : i );
231
+ softly .assertThat (description .getDistance ()).as ("distance " + i ).isEqualTo (Math .min (i , maxDepth ));
232
+ git .commit ().setMessage ("commit " + (i + 1 )).setAllowEmpty (true ).call ();
233
+ }
234
+ softly .assertAll ();
235
+ }
217
236
}
0 commit comments