@@ -326,15 +326,8 @@ void checkout(Git git, Repository gitRepo, String branchName) throws Exception {
326
326
.pull ()
327
327
.setCredentialsProvider (credentials )
328
328
.call ();
329
- CheckoutCommand cmd = git
330
- .checkout ();
331
- Ref ref = gitRepo .exactRef ("refs/heads/" + bn );
332
- if (ref == null ) {
333
- cmd = cmd
334
- .setCreateBranch (true )
335
- .setStartPoint ("origin/" + bn );
336
- }
337
- cmd
329
+ git
330
+ .checkout ()
338
331
.setName (bn )
339
332
.call ();
340
333
}
@@ -688,18 +681,22 @@ public List<VCSTag> getTags() {
688
681
} catch (Exception e ) {
689
682
throw new RuntimeException (e );
690
683
}
691
-
692
684
}
693
685
694
686
List <Ref > getTagRefs () throws Exception {
695
- return new ArrayList <>(Git
696
- .lsRemoteRepository ()
697
- .setTags (true )
698
- .setHeads (false )
699
- .setRemote (repo .getRepoUrl ())
700
- .setCredentialsProvider (credentials )
701
- .call ());
687
+ try (IVCSLockedWorkingCopy wc = repo .getVCSLockedWorkingCopy ();
688
+ Git git = getLocalGit (wc );
689
+ Repository gitRepo = git .getRepository ()) {
690
+
691
+ checkout (git , gitRepo , MASTER_BRANCH_NAME );
692
+
693
+ List <Ref > refs = git
694
+ .tagList ()
695
+ .call ();
696
+
697
+ return refs ;
702
698
}
699
+ }
703
700
704
701
@ Override
705
702
public VCSTag getLastTag () {
@@ -719,11 +716,12 @@ public VCSTag getLastTag() {
719
716
720
717
Collections .sort (tagRefs , new Comparator <Ref >() {
721
718
public int compare (Ref o1 , Ref o2 ) {
722
- try {
719
+ try (Repository gitRepo = git .getRepository ();
720
+ RevWalk rw = new RevWalk (gitRepo )) { // for exception rethrow test only
723
721
Date d1 = rw .parseTag (o1 .getObjectId ()).getTaggerIdent ().getWhen ();
724
722
Date d2 = rw .parseTag (o2 .getObjectId ()).getTaggerIdent ().getWhen ();
725
723
return d1 .compareTo (d2 );
726
- } catch (IOException e ) {
724
+ } catch (Exception e ) {
727
725
throw new RuntimeException (e );
728
726
}
729
727
}
@@ -757,8 +755,8 @@ public void removeTag(String tagName) {
757
755
.tagDelete ()
758
756
.setTags (tagName )
759
757
.call ();
760
-
761
- push (git , null );
758
+
759
+ push (git , new RefSpec ( ":refs/tags/" + tagName ) );
762
760
763
761
} catch (GitAPIException e ) {
764
762
throw new EVCSException (e );
0 commit comments