13
13
import java .util .Set ;
14
14
15
15
import org .apache .commons .io .FileUtils ;
16
+ import org .apache .commons .lang3 .StringUtils ;
16
17
import org .scm4j .vcs .api .IVCS ;
17
18
import org .scm4j .vcs .api .VCSChangeType ;
18
19
import org .scm4j .vcs .api .VCSCommit ;
@@ -451,12 +452,16 @@ public List<VCSDiffEntry> getBranchesDiff(final String srcBranchName, final Stri
451
452
public Set <String > getBranches (String path ) {
452
453
try {
453
454
List <String > entries = listEntries (SVNVCS .BRANCHES_PATH , path == null ? "" : path );
454
- Set <String > res = new HashSet <>(entries );
455
+ Set <String > tempRes = new HashSet <>(entries );
455
456
if (repository .checkPath (MASTER_PATH , -1 ) == SVNNodeKind .DIR ) {
456
457
if (path == null || MASTER_PATH .startsWith (path ) ) {
457
- res .add (MASTER_PATH .replace ("/" , "" ));
458
+ tempRes .add (MASTER_PATH .replace ("/" , "" ));
458
459
}
459
460
}
461
+ Set <String > res = new HashSet <>();
462
+ for (String str : tempRes ) {
463
+ res .add (StringUtils .removeStart (str , SVNVCS .BRANCHES_PATH ));
464
+ }
460
465
return res ;
461
466
} catch (SVNException e ) {
462
467
throw new EVCSException (e );
@@ -465,13 +470,13 @@ public Set<String> getBranches(String path) {
465
470
}
466
471
}
467
472
468
- protected List <String > listEntries (String path , String subdir ) throws Exception {
473
+ protected List <String > listEntries (String path , String subdirStartsWith ) throws Exception {
469
474
List <String > res = new ArrayList <>();
470
- if (repository .checkPath (path + subdir , -1 ) == SVNNodeKind .NONE ) {
475
+ if (repository .checkPath (path , -1 ) == SVNNodeKind .NONE ) {
471
476
return res ;
472
477
}
473
478
@ 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 );
475
480
List <SVNDirEntry > list = new ArrayList <>(subEntries );
476
481
Collections .sort (list , new Comparator <SVNDirEntry >() {
477
482
@ Override
@@ -486,9 +491,8 @@ public int compare(SVNDirEntry o1, SVNDirEntry o2) {
486
491
}
487
492
});
488
493
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 ());
492
496
}
493
497
}
494
498
return res ;
@@ -634,21 +638,20 @@ public Boolean fileExists(String branchName, String filePath) {
634
638
635
639
@ Override
636
640
public VCSTag createTag (String branchName , String tagName , String tagMessage , String revisionToTag ) throws EVCSTagExists {
637
- try {
641
+ try ( IVCSLockedWorkingCopy wc = repo . getVCSLockedWorkingCopy ()) {
638
642
SVNURL srcURL = getBranchUrl (branchName );
639
643
SVNURL dstURL = SVNURL .parseURIEncoded (repoUrl + TAGS_PATH + tagName );
644
+ SVNLogEntry copyFromEntry = revToSVNEntry (getBranchName (branchName ),
645
+ revisionToTag == null ? SVNRevision .HEAD .getNumber () : Long .parseLong (revisionToTag ));
640
646
SVNCopySource copySource = revisionToTag == null ?
641
- new SVNCopySource (SVNRevision .HEAD , SVNRevision .HEAD , srcURL ) :
647
+ new SVNCopySource (SVNRevision .HEAD , SVNRevision .create ( copyFromEntry . getRevision ()) , srcURL ) :
642
648
new SVNCopySource (SVNRevision .parse (revisionToTag ), SVNRevision .parse (revisionToTag ), srcURL );
643
649
644
650
clientManager .getCopyClient ().doCopy (new SVNCopySource [] {copySource }, dstURL ,
645
651
false , false , true , tagMessage , null );
646
-
652
+
647
653
SVNDirEntry entry = repository .info (TAGS_PATH + tagName , -1 );
648
654
649
- SVNLogEntry copyFromEntry = revToSVNEntry (getBranchName (branchName ),
650
- revisionToTag == null ? SVNRevision .HEAD .getNumber () : Long .parseLong (revisionToTag ));
651
-
652
655
return new VCSTag (tagName , tagMessage , entry .getAuthor (), svnLogEntryToVCSCommit (copyFromEntry ));
653
656
} catch (SVNException e ) {
654
657
if (e .getErrorMessage ().getErrorCode ().getCode () == SVN_ITEM_EXISTS_ERROR_CODE ) {
@@ -691,10 +694,11 @@ public void handleLogEntry(SVNLogEntry logEntry) throws SVNException {
691
694
public List <VCSTag > getTags () {
692
695
try {
693
696
List <String > entries = listEntries (TAGS_PATH , "" );
697
+
694
698
List <VCSTag > res = new ArrayList <>();
695
699
SVNTagBaseCommit handler ;
696
700
for (String entryStr : entries ) {
697
-
701
+
698
702
SVNLogEntry entry = revToSVNEntry (entryStr , -1L );
699
703
700
704
handler = new SVNTagBaseCommit ();
0 commit comments