1313import java .util .Set ;
1414
1515import org .apache .commons .io .FileUtils ;
16+ import org .apache .commons .lang3 .StringUtils ;
1617import org .scm4j .vcs .api .IVCS ;
1718import org .scm4j .vcs .api .VCSChangeType ;
1819import org .scm4j .vcs .api .VCSCommit ;
@@ -451,12 +452,16 @@ public List<VCSDiffEntry> getBranchesDiff(final String srcBranchName, final Stri
451452 public Set <String > getBranches (String path ) {
452453 try {
453454 List <String > entries = listEntries (SVNVCS .BRANCHES_PATH , path == null ? "" : path );
454- Set <String > res = new HashSet <>(entries );
455+ Set <String > tempRes = new HashSet <>(entries );
455456 if (repository .checkPath (MASTER_PATH , -1 ) == SVNNodeKind .DIR ) {
456457 if (path == null || MASTER_PATH .startsWith (path ) ) {
457- res .add (MASTER_PATH .replace ("/" , "" ));
458+ tempRes .add (MASTER_PATH .replace ("/" , "" ));
458459 }
459460 }
461+ Set <String > res = new HashSet <>();
462+ for (String str : tempRes ) {
463+ res .add (StringUtils .removeStart (str , SVNVCS .BRANCHES_PATH ));
464+ }
460465 return res ;
461466 } catch (SVNException e ) {
462467 throw new EVCSException (e );
@@ -465,13 +470,13 @@ public Set<String> getBranches(String path) {
465470 }
466471 }
467472
468- protected List <String > listEntries (String path , String subdir ) throws Exception {
473+ protected List <String > listEntries (String path , String subdirStartsWith ) throws Exception {
469474 List <String > res = new ArrayList <>();
470- if (repository .checkPath (path + subdir , -1 ) == SVNNodeKind .NONE ) {
475+ if (repository .checkPath (path , -1 ) == SVNNodeKind .NONE ) {
471476 return res ;
472477 }
473478 @ SuppressWarnings ("unchecked" )
474- Collection <SVNDirEntry > subEntries = repository .getDir (path + subdir , -1 , null , (Collection <SVNDirEntry >) null );
479+ Collection <SVNDirEntry > subEntries = repository .getDir (path , -1 , null , (Collection <SVNDirEntry >) null );
475480 List <SVNDirEntry > list = new ArrayList <>(subEntries );
476481 Collections .sort (list , new Comparator <SVNDirEntry >() {
477482 @ Override
@@ -486,9 +491,8 @@ public int compare(SVNDirEntry o1, SVNDirEntry o2) {
486491 }
487492 });
488493 for (SVNDirEntry entry : list ) {
489- if (entry .getKind () == SVNNodeKind .DIR ) {
490- res .add (((path .equals (SVNVCS .BRANCHES_PATH ) ? "" : path ) + subdir + entry .getName ())
491- .replace (SVNVCS .BRANCHES_PATH , "" ));
494+ if (entry .getKind () == SVNNodeKind .DIR && entry .getName ().startsWith (subdirStartsWith )) {
495+ res .add (path + entry .getName ());
492496 }
493497 }
494498 return res ;
@@ -634,21 +638,20 @@ public Boolean fileExists(String branchName, String filePath) {
634638
635639 @ Override
636640 public VCSTag createTag (String branchName , String tagName , String tagMessage , String revisionToTag ) throws EVCSTagExists {
637- try {
641+ try ( IVCSLockedWorkingCopy wc = repo . getVCSLockedWorkingCopy ()) {
638642 SVNURL srcURL = getBranchUrl (branchName );
639643 SVNURL dstURL = SVNURL .parseURIEncoded (repoUrl + TAGS_PATH + tagName );
644+ SVNLogEntry copyFromEntry = revToSVNEntry (getBranchName (branchName ),
645+ revisionToTag == null ? SVNRevision .HEAD .getNumber () : Long .parseLong (revisionToTag ));
640646 SVNCopySource copySource = revisionToTag == null ?
641- new SVNCopySource (SVNRevision .HEAD , SVNRevision .HEAD , srcURL ) :
647+ new SVNCopySource (SVNRevision .HEAD , SVNRevision .create ( copyFromEntry . getRevision ()) , srcURL ) :
642648 new SVNCopySource (SVNRevision .parse (revisionToTag ), SVNRevision .parse (revisionToTag ), srcURL );
643649
644650 clientManager .getCopyClient ().doCopy (new SVNCopySource [] {copySource }, dstURL ,
645651 false , false , true , tagMessage , null );
646-
652+
647653 SVNDirEntry entry = repository .info (TAGS_PATH + tagName , -1 );
648654
649- SVNLogEntry copyFromEntry = revToSVNEntry (getBranchName (branchName ),
650- revisionToTag == null ? SVNRevision .HEAD .getNumber () : Long .parseLong (revisionToTag ));
651-
652655 return new VCSTag (tagName , tagMessage , entry .getAuthor (), svnLogEntryToVCSCommit (copyFromEntry ));
653656 } catch (SVNException e ) {
654657 if (e .getErrorMessage ().getErrorCode ().getCode () == SVN_ITEM_EXISTS_ERROR_CODE ) {
@@ -691,10 +694,11 @@ public void handleLogEntry(SVNLogEntry logEntry) throws SVNException {
691694 public List <VCSTag > getTags () {
692695 try {
693696 List <String > entries = listEntries (TAGS_PATH , "" );
697+
694698 List <VCSTag > res = new ArrayList <>();
695699 SVNTagBaseCommit handler ;
696700 for (String entryStr : entries ) {
697-
701+
698702 SVNLogEntry entry = revToSVNEntry (entryStr , -1L );
699703
700704 handler = new SVNTagBaseCommit ();
0 commit comments