33import java .io .ByteArrayOutputStream ;
44import java .io .File ;
55import java .io .FileWriter ;
6+ import java .net .URL ;
67import java .nio .charset .StandardCharsets ;
78import java .util .ArrayList ;
89import java .util .Collection ;
1314import java .util .Set ;
1415
1516import org .apache .commons .io .FileUtils ;
17+ import org .apache .commons .lang3 .StringUtils ;
1618import org .scm4j .vcs .api .IVCS ;
1719import org .scm4j .vcs .api .VCSChangeType ;
1820import org .scm4j .vcs .api .VCSCommit ;
5961import org .tmatesoft .svn .core .wc .SVNWCClient ;
6062import org .tmatesoft .svn .core .wc .SVNWCUtil ;
6163import org .tmatesoft .svn .core .wc2 .ISvnObjectReceiver ;
64+ import org .tmatesoft .svn .core .wc2 .SvnCopySource ;
6265import org .tmatesoft .svn .core .wc2 .SvnDiff ;
6366import org .tmatesoft .svn .core .wc2 .SvnDiffStatus ;
6467import org .tmatesoft .svn .core .wc2 .SvnDiffSummarize ;
6568import org .tmatesoft .svn .core .wc2 .SvnOperationFactory ;
69+ import org .tmatesoft .svn .core .wc2 .SvnRemoteCopy ;
6670import org .tmatesoft .svn .core .wc2 .SvnTarget ;
6771
6872public class SVNVCS implements IVCS {
@@ -451,12 +455,16 @@ public List<VCSDiffEntry> getBranchesDiff(final String srcBranchName, final Stri
451455 public Set <String > getBranches (String path ) {
452456 try {
453457 List <String > entries = listEntries (SVNVCS .BRANCHES_PATH , path == null ? "" : path );
454- Set <String > res = new HashSet <>(entries );
458+ Set <String > tempRes = new HashSet <>(entries );
455459 if (repository .checkPath (MASTER_PATH , -1 ) == SVNNodeKind .DIR ) {
456460 if (path == null || MASTER_PATH .startsWith (path ) ) {
457- res .add (MASTER_PATH .replace ("/" , "" ));
461+ tempRes .add (MASTER_PATH .replace ("/" , "" ));
458462 }
459463 }
464+ Set <String > res = new HashSet <>();
465+ for (String str : tempRes ) {
466+ res .add (StringUtils .removeStart (StringUtils .removeStart (str , SVNVCS .BRANCHES_PATH ), path ));
467+ }
460468 return res ;
461469 } catch (SVNException e ) {
462470 throw new EVCSException (e );
@@ -465,13 +473,13 @@ public Set<String> getBranches(String path) {
465473 }
466474 }
467475
468- protected List <String > listEntries (String path , String subdir ) throws Exception {
476+ protected List <String > listEntries (String path , String subdirStartsWith ) throws Exception {
469477 List <String > res = new ArrayList <>();
470- if (repository .checkPath (path + subdir , -1 ) == SVNNodeKind .NONE ) {
478+ if (repository .checkPath (path , -1 ) == SVNNodeKind .NONE ) {
471479 return res ;
472480 }
473481 @ SuppressWarnings ("unchecked" )
474- Collection <SVNDirEntry > subEntries = repository .getDir (path + subdir , -1 , null , (Collection <SVNDirEntry >) null );
482+ Collection <SVNDirEntry > subEntries = repository .getDir (path , -1 , null , (Collection <SVNDirEntry >) null );
475483 List <SVNDirEntry > list = new ArrayList <>(subEntries );
476484 Collections .sort (list , new Comparator <SVNDirEntry >() {
477485 @ Override
@@ -486,9 +494,8 @@ public int compare(SVNDirEntry o1, SVNDirEntry o2) {
486494 }
487495 });
488496 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 , "" ));
497+ if (entry .getKind () == SVNNodeKind .DIR && entry .getName ().startsWith (subdirStartsWith )) {
498+ res .add (path + entry .getName ());
492499 }
493500 }
494501 return res ;
@@ -634,20 +641,29 @@ public Boolean fileExists(String branchName, String filePath) {
634641
635642 @ Override
636643 public VCSTag createTag (String branchName , String tagName , String tagMessage , String revisionToTag ) throws EVCSTagExists {
637- try {
644+ try (IVCSLockedWorkingCopy wc = repo .getVCSLockedWorkingCopy ()) {
645+ //checkout(getBranchUrl(branchName), wc.getFolder(), null);
638646 SVNURL srcURL = getBranchUrl (branchName );
639647 SVNURL dstURL = SVNURL .parseURIEncoded (repoUrl + TAGS_PATH + tagName );
640648 SVNCopySource copySource = revisionToTag == null ?
641649 new SVNCopySource (SVNRevision .HEAD , SVNRevision .HEAD , srcURL ) :
642650 new SVNCopySource (SVNRevision .parse (revisionToTag ), SVNRevision .parse (revisionToTag ), srcURL );
643651
644- clientManager .getCopyClient ().doCopy (new SVNCopySource [] {copySource }, dstURL ,
645- false , false , true , tagMessage , null );
646-
652+ SvnRemoteCopy tagOperation = new SvnOperationFactory ().createRemoteCopy ();
653+ SvnCopySource source = SvnCopySource .create (SvnTarget .fromURL (srcURL ), SVNRevision .UNDEFINED );
654+ tagOperation .addCopySource (source );
655+ tagOperation .setSingleTarget (SvnTarget .fromURL (dstURL ));
656+ tagOperation .setFailWhenDstExists (true );
657+ tagOperation .setCommitMessage (tagMessage );
658+ tagOperation .run ();
659+ //
660+ // clientManager.getCopyClient().doCopy(new SVNCopySource[] {copySource}, dstURL,
661+ // false, false, true, tagMessage, null);
662+
647663 SVNDirEntry entry = repository .info (TAGS_PATH + tagName , -1 );
648664
649665 SVNLogEntry copyFromEntry = revToSVNEntry (getBranchName (branchName ),
650- revisionToTag == null ? SVNRevision .HEAD .getNumber () : Long .parseLong (revisionToTag ));
666+ revisionToTag == null ? SVNRevision .BASE .getNumber () : Long .parseLong (revisionToTag ));
651667
652668 return new VCSTag (tagName , tagMessage , entry .getAuthor (), svnLogEntryToVCSCommit (copyFromEntry ));
653669 } catch (SVNException e ) {
@@ -691,10 +707,11 @@ public void handleLogEntry(SVNLogEntry logEntry) throws SVNException {
691707 public List <VCSTag > getTags () {
692708 try {
693709 List <String > entries = listEntries (TAGS_PATH , "" );
710+
694711 List <VCSTag > res = new ArrayList <>();
695712 SVNTagBaseCommit handler ;
696713 for (String entryStr : entries ) {
697-
714+
698715 SVNLogEntry entry = revToSVNEntry (entryStr , -1L );
699716
700717 handler = new SVNTagBaseCommit ();
0 commit comments