@@ -729,7 +729,9 @@ public VCSTag createTag(String branchName, String tagName, String tagMessage, St
729729 Repository gitRepo = git .getRepository ();
730730 RevWalk rw = new RevWalk (gitRepo )) {
731731
732- checkout (git , gitRepo , branchName , null );
732+ git
733+ .pull ()
734+ .call ();
733735
734736 RevCommit commitToTag = revisionToTag == null ? null : rw .parseCommit (ObjectId .fromString (revisionToTag ));
735737
@@ -763,9 +765,7 @@ public List<VCSTag> getTags() {
763765 Repository gitRepo = git .getRepository ();
764766 RevWalk rw = new RevWalk (gitRepo )) {
765767
766- git .pull ().call ();
767-
768- List <Ref > tagRefs = getTagRefs ();
768+ List <Ref > tagRefs = getTagRefs (git );
769769 List <VCSTag > res = new ArrayList <>();
770770 RevCommit revCommit ;
771771 for (Ref ref : tagRefs ) {
@@ -778,6 +778,7 @@ public List<VCSTag> getTags() {
778778 RevTag revTag = (RevTag ) revObject ;
779779 tag = new VCSTag (revTag .getTagName (), revTag .getFullMessage (), revTag .getTaggerIdent ().getName (), relatedCommit );
780780 } else {
781+ // tag is unannotated
781782 tag = new VCSTag (ref .getName ().replace ("refs/tags/" , "" ), null , null , relatedCommit );
782783 }
783784 res .add (tag );
@@ -788,19 +789,17 @@ public List<VCSTag> getTags() {
788789 }
789790 }
790791
791- List <Ref > getTagRefs () throws Exception {
792- try (IVCSLockedWorkingCopy wc = repo .getVCSLockedWorkingCopy ();
793- Git git = getLocalGit (wc );
794- Repository gitRepo = git .getRepository ()) {
795-
796- git .pull ().call ();
797-
798- List <Ref > refs = git
799- .tagList ()
800- .call ();
801-
802- return refs ;
803- }
792+ private List <Ref > getTagRefs (Git git ) throws Exception {
793+ // need to remove tags from local repo which are removed in origin
794+ git
795+ .fetch ()
796+ .setRefSpecs (new RefSpec ("+refs/tags/*:refs/tags/*" ))
797+ .setRemoveDeletedRefs (true )
798+ .setCredentialsProvider (credentials )
799+ .call ();
800+ return git
801+ .tagList ()
802+ .call ();
804803 }
805804
806805 @ Override
@@ -810,15 +809,16 @@ public void removeTag(String tagName) {
810809 Repository gitRepo = git .getRepository ();
811810 RevWalk rw = new RevWalk (gitRepo )) {
812811
813- checkout ( git , gitRepo , MASTER_BRANCH_NAME , null );
814-
812+ git . pull (). call ( );
813+
815814 git
816815 .tagDelete ()
817816 .setTags (tagName )
818817 .call ();
819-
818+
820819 push (git , new RefSpec (":refs/tags/" + tagName ));
821820
821+
822822 } catch (GitAPIException e ) {
823823 throw new EVCSException (e );
824824 } catch (Exception e ) {
@@ -848,10 +848,8 @@ public List<VCSTag> getTagsOnRevision(String revision) {
848848 RevWalk rw = new RevWalk (gitRepo )) {
849849
850850 List <VCSTag > res = new ArrayList <>();
851-
852- git .pull ().call ();
853851
854- List <Ref > tagRefs = getTagRefs ();
852+ List <Ref > tagRefs = getTagRefs (git );
855853 RevCommit revCommit ;
856854 for (Ref ref : tagRefs ) {
857855 ObjectId relatedCommitObjectId = ref .getPeeledObjectId () == null ? ref .getObjectId () : ref .getPeeledObjectId ();
0 commit comments