Skip to content

Commit 1aedee8

Browse files
committed
getTagsOnRevision() fixed
getBranches() fixed
1 parent bc7a3c1 commit 1aedee8

File tree

3 files changed

+63
-18
lines changed

3 files changed

+63
-18
lines changed

build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,10 @@ dependencies {
4848
add(configuration ?: name.contains('test') ? 'testCompile' : 'compile', "$group:$name:${version?:''}${classifier?:''}${ext?:''}")
4949
}
5050

51-
//compile 'com.github.scm4j:scm4j-vcs-api:master-SNAPSHOT'
5251
compile 'org.tmatesoft.svnkit:svnkit:1.8.14'
5352
compile 'org.apache.commons:commons-lang3:3.5'
5453

5554
testCompile 'junit:junit:4.12'
56-
//testCompile 'com.github.scm4j:scm4j-vcs-test:master-SNAPSHOT'
5755
testCompile 'org.mockito:mockito-core:2.0.62-beta'
5856
}
5957

src/main/java/org/scm4j/vcs/svn/SVNVCS.java

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.Collections;
1010
import java.util.Comparator;
1111
import java.util.HashSet;
12+
import java.util.Iterator;
1213
import java.util.List;
1314
import java.util.Set;
1415

@@ -451,7 +452,7 @@ public List<VCSDiffEntry> getBranchesDiff(final String srcBranchName, final Stri
451452
@Override
452453
public Set<String> getBranches(String path) {
453454
try {
454-
List<String> entries = listEntries(SVNVCS.BRANCHES_PATH, path == null ? "" : path);
455+
List<String> entries = listEntries(SVNVCS.BRANCHES_PATH + (path == null ? "" : path));
455456
Set<String> tempRes = new HashSet<>(entries);
456457
if (repository.checkPath(MASTER_PATH, -1) == SVNNodeKind.DIR) {
457458
if (path == null || MASTER_PATH.startsWith(path) ) {
@@ -470,15 +471,15 @@ public Set<String> getBranches(String path) {
470471
}
471472
}
472473

473-
protected List<String> listEntries(String path, String subdirStartsWith) throws Exception {
474+
protected List<String> listEntries(String path) throws Exception {
474475
List<String> res = new ArrayList<>();
475-
if (repository.checkPath(path , -1) == SVNNodeKind.NONE) {
476+
if (repository.checkPath(path , -1) == SVNNodeKind.NONE) {
476477
return res;
477478
}
478479
@SuppressWarnings("unchecked")
479-
Collection<SVNDirEntry> subEntries = repository.getDir(path, -1, null, (Collection<SVNDirEntry>) null);
480-
List<SVNDirEntry> list = new ArrayList<>(subEntries);
481-
Collections.sort(list, new Comparator<SVNDirEntry>() {
480+
Collection<SVNDirEntry> entries = repository.getDir(path, -1 , null , (Collection<SVNDirEntry>) null);
481+
List<SVNDirEntry> entriesList = new ArrayList<>(entries);
482+
Collections.sort(entriesList, new Comparator<SVNDirEntry>() {
482483
@Override
483484
public int compare(SVNDirEntry o1, SVNDirEntry o2) {
484485
if (o1.getRevision() < o2.getRevision()) {
@@ -490,11 +491,16 @@ public int compare(SVNDirEntry o1, SVNDirEntry o2) {
490491
return 0;
491492
}
492493
});
493-
for (SVNDirEntry entry : list) {
494-
if (entry.getKind() == SVNNodeKind.DIR && entry.getName().startsWith(subdirStartsWith)) {
495-
res.add(path + entry.getName());
494+
Iterator<SVNDirEntry> entriesIterator = entriesList.iterator();
495+
while (entriesIterator.hasNext()) {
496+
SVNDirEntry entry = (SVNDirEntry) entriesIterator.next();
497+
498+
if (entry.getKind() == SVNNodeKind.DIR) {
499+
res.add((path.isEmpty() ? "" : StringUtils.appendIfMissing(path, "/")) + entry.getName());
500+
res.addAll(listEntries((path.equals("")) ? entry.getName( ) : path + entry.getName()));
496501
}
497502
}
503+
498504
return res;
499505
}
500506

@@ -693,7 +699,7 @@ public void handleLogEntry(SVNLogEntry logEntry) throws SVNException {
693699
@Override
694700
public List<VCSTag> getTags() {
695701
try {
696-
List<String> entries = listEntries(TAGS_PATH, "");
702+
List<String> entries = listEntries(TAGS_PATH);
697703

698704
List<VCSTag> res = new ArrayList<>();
699705
SVNTagBaseCommit handler;
@@ -748,8 +754,19 @@ public void checkout(String branchName, String targetPath, String revision) {
748754
@Override
749755
public List<VCSTag> getTagsOnRevision(String revision) {
750756
try {
751-
List<String> tagEntries = listEntries(TAGS_PATH, "");
752757
List<VCSTag> res = new ArrayList<>();
758+
if (repository.checkPath(TAGS_PATH , -1) == SVNNodeKind.NONE) {
759+
return res;
760+
}
761+
List<String> tagEntries = new ArrayList<>();
762+
@SuppressWarnings("unchecked")
763+
Collection<SVNDirEntry> entries = repository.getDir(TAGS_PATH, -1 , null , (Collection<SVNDirEntry>) null);
764+
for (SVNDirEntry entry : entries) {
765+
if (entry.getKind() == SVNNodeKind.DIR) {
766+
tagEntries.add(TAGS_PATH + entry.getName());
767+
}
768+
}
769+
753770
SVNTagBaseCommit handler;
754771
for (String tagEntryStr : tagEntries) {
755772

src/test/java/org/scm4j/vcs/svn/SVNVCSTest.java

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ private void testExceptionThrowing(Exception testException, Method m, Object[] p
175175
reset(svn);
176176
doThrow(testException).when(svn).checkout(any(SVNURL.class), any(File.class), (String) isNull());
177177
doThrow(testException).when(svn).getBranchUrl(null);
178-
doThrow(testException).when(svn).listEntries(anyString(), anyString());
178+
doThrow(testException).when(svn).listEntries(anyString());
179179
doThrow(testException).when(svn).getBranchFirstCommit(null);
180180
doThrow(testException).when(svn).revToSVNEntry(anyString(), any(Long.class));
181181
try {
@@ -207,7 +207,7 @@ private boolean wasMockedMethodInvoked() throws Exception {
207207
} catch (WantedButNotInvoked e1) {
208208
}
209209
try {
210-
verify(svn).listEntries(anyString(), anyString());
210+
verify(svn).listEntries(anyString());
211211
return true;
212212
} catch (WantedButNotInvoked e1) {
213213
}
@@ -401,12 +401,12 @@ public void testListEntriesSorting() throws Exception {
401401
doReturn(Arrays.asList(entry1, entry2)).when(mockedRepo).getDir(anyString(), anyLong(), any(SVNProperties.class),
402402
Matchers.<Collection<SVNDirEntry>>any());
403403

404-
List<String> entries = svn.listEntries("", "");
404+
List<String> entries = svn.listEntries("");
405405
assertEquals(entries.get(0), entry1.getName());
406406
assertEquals(entries.get(1), entry2.getName());
407407
doReturn(Arrays.asList(entry1, entry1)).when(mockedRepo).getDir(anyString(), anyLong(), any(SVNProperties.class),
408408
Matchers.<Collection<SVNDirEntry>>any());
409-
entries = svn.listEntries("", "");
409+
entries = svn.listEntries("");
410410
assertEquals(entries.get(0), entry1.getName());
411411
assertEquals(entries.get(1), entry1.getName());
412412
}
@@ -436,6 +436,36 @@ public void testListEntriesNone() throws Exception {
436436
SVNRepository mockedRepo = spy(svn.getSVNRepository());
437437
svn.setSVNRepository(mockedRepo);
438438
doReturn(SVNNodeKind.NONE).when(mockedRepo).checkPath((String) isNull(), anyLong());
439-
svn.listEntries(null, null); // expecting no NPE
439+
svn.listEntries(null); // expecting no NPE
440+
}
441+
442+
@Test
443+
public void testGetTagsOnRevisionNoTagsDir() throws SVNException {
444+
svn.getClientManager()
445+
.getCommitClient()
446+
.doDelete(new SVNURL[] { SVNURL.parseURIEncoded(svn.getRepoUrl() + "/" + SVNVCS.TAGS_PATH)}, "tags/ deleted");
447+
assertTrue(vcs.getTagsOnRevision("0").isEmpty());
448+
}
449+
450+
@Test
451+
public void testGetTagsOnRevisionExceptions() throws Exception {
452+
SVNRepository mockedRepo = spy(svn.getSVNRepository());
453+
svn.setSVNRepository(mockedRepo);
454+
vcs.createTag(null, TAG_NAME_1, TAG_MESSAGE_1, null);
455+
doThrow(testCommonException).when(svn).revToSVNEntry(anyString(), anyLong());
456+
try {
457+
vcs.getTagsOnRevision("");
458+
fail();
459+
} catch (RuntimeException e) {
460+
checkCommonException(e);
461+
}
462+
463+
doThrow(testSVNException).when(mockedRepo).checkPath(anyString(), anyLong());
464+
try {
465+
vcs.getTagsOnRevision("");
466+
fail();
467+
} catch (EVCSException e) {
468+
checkEVCSException(e);
469+
}
440470
}
441471
}

0 commit comments

Comments
 (0)