Skip to content

Commit 2651aee

Browse files
committed
createTag() fixed
checkout() fixed
1 parent e72afd3 commit 2651aee

File tree

2 files changed

+45
-18
lines changed

2 files changed

+45
-18
lines changed

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

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public void createBranch(String srcBranchName, String dstBranchName, String comm
110110

111111
public void createBranch(SVNURL fromUrl, SVNURL toUrl, String commitMessage) {
112112
try (IVCSLockedWorkingCopy wc = repo.getVCSLockedWorkingCopy()) {
113-
checkout(fromUrl, wc.getFolder());
113+
checkout(fromUrl, wc.getFolder(), null);
114114

115115
SVNCopyClient copyClient = new SVNCopyClient(authManager, options);
116116
SVNCopySource copySource = new SVNCopySource(SVNRevision.WORKING, SVNRevision.WORKING,
@@ -151,7 +151,7 @@ public void deleteBranch(String branchName, String commitMessage) {
151151
public VCSMergeResult merge(String srcBranchName, String dstBranchName, String commitMessage) {
152152
SVNDiffClient diffClient = clientManager.getDiffClient();
153153
try (IVCSLockedWorkingCopy wc = repo.getVCSLockedWorkingCopy()) {
154-
checkout(getBranchUrl(dstBranchName), wc.getFolder());
154+
checkout(getBranchUrl(dstBranchName), wc.getFolder(), null);
155155

156156
DefaultSVNOptions options = (DefaultSVNOptions) diffClient.getOptions();
157157
final List<String> conflictingFiles = new ArrayList<>();
@@ -203,14 +203,14 @@ public SVNWCClient getRevertClient(DefaultSVNOptions options) {
203203
return new SVNWCClient(authManager, options);
204204
}
205205

206-
public void checkout(SVNURL sourceUrl, File destPath) throws Exception {
206+
public void checkout(SVNURL sourceUrl, File destPath, String revision) throws Exception {
207207
SVNUpdateClient updateClient = clientManager.getUpdateClient();
208208
updateClient.setIgnoreExternals(false);
209+
SVNRevision svnRevision = revision == null ? SVNRevision.HEAD : SVNRevision.parse(revision);
209210
if (isWorkingCopyInited(destPath)) {
210-
updateClient.doSwitch(destPath, sourceUrl, SVNRevision.HEAD,
211-
SVNRevision.HEAD, SVNDepth.INFINITY, false, false);
211+
updateClient.doSwitch(destPath, sourceUrl, svnRevision, svnRevision, SVNDepth.INFINITY, false, false);
212212
} else {
213-
updateClient.doCheckout(sourceUrl, destPath, SVNRevision.HEAD, SVNRevision.HEAD, SVNDepth.UNKNOWN, false);
213+
updateClient.doCheckout(sourceUrl, destPath, svnRevision, svnRevision, SVNDepth.UNKNOWN, false);
214214
}
215215
}
216216

@@ -232,6 +232,8 @@ public void setCredentials(String user, String password) {
232232
userPassAuth = SVNPasswordAuthentication.newInstance(user, password == null ? null : password.toCharArray(),
233233
true, trunkSVNUrl, false);
234234
authManager.setAuthentications(new SVNAuthentication[] {userPassAuth});
235+
clientManager = SVNClientManager.newInstance(
236+
options, repository.getAuthenticationManager());
235237
}
236238

237239
@Override
@@ -269,7 +271,7 @@ public String getFileContent(String branchName, String filePath) {
269271
@Override
270272
public VCSCommit setFileContent(String branchName, String filePath, String content, String commitMessage) {
271273
try (IVCSLockedWorkingCopy wc = repo.getVCSLockedWorkingCopy()) {
272-
checkout(getBranchUrl(branchName), wc.getFolder());
274+
checkout(getBranchUrl(branchName), wc.getFolder(), null);
273275
File file = new File(wc.getFolder(), filePath);
274276
Boolean needToAdd = !file.exists();
275277
if (!file.exists()) {
@@ -399,7 +401,7 @@ public VCSChangeType SVNChangeTypeToVCSChangeType(SVNStatusType modificationType
399401
@Override
400402
public List<VCSDiffEntry> getBranchesDiff(final String srcBranchName, final String dstBranchName) {
401403
try (IVCSLockedWorkingCopy wc = repo.getVCSLockedWorkingCopy()) {
402-
checkout(getBranchUrl(dstBranchName), wc.getFolder());
404+
checkout(getBranchUrl(dstBranchName), wc.getFolder(), null);
403405
List<VCSDiffEntry> entries = getDiffEntries(srcBranchName, dstBranchName);
404406
entries = fillUnifiedDiffs(srcBranchName, dstBranchName, entries);
405407
return entries;
@@ -602,12 +604,13 @@ public Boolean fileExists(String branchName, String filePath) {
602604
}
603605

604606
@Override
605-
public VCSTag createTag(String branchName, String tagName, String tagMessage) throws EVCSTagExists {
607+
public VCSTag createTag(String branchName, String tagName, String tagMessage, String revisionToTag) throws EVCSTagExists {
606608
try {
607609
SVNURL srcURL = getBranchUrl(branchName);
608-
SVNURL dstURL = SVNURL.parseURIEncoded(repoUrl + TAGS_PATH + tagName);
609-
SVNCopySource copySource =
610-
new SVNCopySource(SVNRevision.HEAD, SVNRevision.HEAD, srcURL);
610+
SVNURL dstURL = SVNURL.parseURIEncoded(repoUrl + TAGS_PATH + tagName);
611+
SVNCopySource copySource = revisionToTag == null ?
612+
new SVNCopySource(SVNRevision.HEAD, SVNRevision.HEAD, srcURL) :
613+
new SVNCopySource(SVNRevision.parse(revisionToTag), SVNRevision.parse(revisionToTag), srcURL);
611614

612615
clientManager.getCopyClient().doCopy(new SVNCopySource[] {copySource}, dstURL,
613616
false, false, true, tagMessage, null);
@@ -717,11 +720,35 @@ public void removeTag(String tagName) {
717720
}
718721
}
719722

723+
@Override
724+
public void checkout(String branchName, String targetPath, String revision) {
725+
try {
726+
checkout(getBranchUrl(branchName), new File(targetPath), revision);
727+
} catch (SVNException e) {
728+
throw new EVCSException(e);
729+
} catch (Exception e) {
730+
throw new RuntimeException(e);
731+
}
732+
}
720733

721734
@Override
722-
public void checkout(String branchName, String targetPath) {
735+
public Boolean isRevisionTagged(String revision) {
736+
List<String> entries = new ArrayList<>();
723737
try {
724-
checkout(getBranchUrl(branchName), new File(targetPath));
738+
listEntries(entries, TAGS_PATH, "");
739+
SVNTagBaseCommit handler;
740+
for (String entryStr : entries) {
741+
handler = new SVNTagBaseCommit();
742+
743+
repository.log(new String[] { entryStr }, -1 /* start from head descending */,
744+
0, true, true, -1, handler);
745+
746+
SVNDirEntry copyFromEntry = repository.info("", handler.copyFromRevision);
747+
if (copyFromEntry.getRevision() == Long.parseLong(revision)) {
748+
return true;
749+
}
750+
}
751+
return false;
725752
} catch (SVNException e) {
726753
throw new EVCSException(e);
727754
} catch (Exception e) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public void testExceptions() throws Exception {
152152

153153
private void testExceptionThrowing(Exception testException, Method m, Object[] params) throws Exception {
154154
reset(svn);
155-
doThrow(testException).when(svn).checkout(any(SVNURL.class), any(File.class));
155+
doThrow(testException).when(svn).checkout(any(SVNURL.class), any(File.class), (String) isNull());
156156
doThrow(testException).when(svn).getBranchUrl(null);
157157
doThrow(testException).when(svn).listEntries(Matchers.<List<String>>any(), anyString(), anyString());
158158
doThrow(testException).when(svn).getBranchFirstCommit(null);
@@ -176,7 +176,7 @@ private void testExceptionThrowing(Exception testException, Method m, Object[] p
176176

177177
private boolean wasMockedMethodInvoked() throws Exception {
178178
try {
179-
verify(svn).checkout(any(SVNURL.class), any(File.class));
179+
verify(svn).checkout(any(SVNURL.class), any(File.class), (String) isNull());
180180
return true;
181181
} catch (WantedButNotInvoked e1) {
182182
}
@@ -224,14 +224,14 @@ public void testDefaultChangeTypeToVCSType() throws IllegalAccessException {
224224

225225
@Test
226226
public void testCreateBranchExceptions() throws Exception {
227-
doThrow(testCommonException).when(svn).checkout(any(SVNURL.class), any(File.class));
227+
doThrow(testCommonException).when(svn).checkout(any(SVNURL.class), any(File.class), (String) isNull());
228228
try {
229229
vcs.createBranch("", "", "");
230230
fail();
231231
} catch (RuntimeException e) {
232232
checkCommonException(e);
233233
}
234-
doThrow(testSVNException).when(svn).checkout(any(SVNURL.class), any(File.class));
234+
doThrow(testSVNException).when(svn).checkout(any(SVNURL.class), any(File.class), (String) isNull());
235235
try {
236236
vcs.createBranch("", "", "");
237237
fail();

0 commit comments

Comments
 (0)