2

Say you have a specified SVN path like below, How can I know this item is a svn directory or a svn file. thanks.

http://cvs-server.test.com:8001/svn/test 

Updated

 SVNURL svnUrl = SVNURL.parseURIEncoded(url); SVNRepository repos = SVNRepositoryFactory.create(svnUrl); ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager("user1","123"); repos.setAuthenticationManager(authManager); SVNNodeKind nodeKind = repos.checkPath(url, repos.getLatestRevision()); 

Why did I get none even the url is a file ? I am sure this url exist in SVN. ORZ... There are many bugs with SVNkit .

2
  • You mean: how to identify that a specific folder on your file system is under version control? You have hidden folder called .svn in the folders which are under version control. Is that what you mean? Commented Nov 16, 2012 at 13:11
  • please review my post . I updated it just now .thanks Commented Nov 16, 2012 at 13:15

3 Answers 3

3

If you encounter into bugs, please report them to http://issues.tmatesoft.com/issues/SVNKIT .

checkPath doesn't work with URLs, it works with paths, absolute (i.e. relative to the repository root) or relative (to the URL for which SVNRepository instance was constructed) --- see its javadoc for more details

So you can just use this code

SVNNodeKind nodeKind = repos.checkPath("", repos.getLatestRevision()); 

or even

SVNNodeKind nodeKind = repos.checkPath("", -1); 

the second variant will be faster because it doesn't perform getLatestRevision request, and it's a rather popular way to check the URL existence that is often used in SVNKit itself.

Alternatively you could use an absolute path (which should start with "/") but the path to be specified depends on your repository root. You can get the repository root by running

$ svn info "http://cvs-server.test.com:8001/svn/test" 

or by running

repos.getRepositoryRoot(true); 

from SVNKit code. The absolute path should start with "/" and be relative to the repository root obtained.

Sign up to request clarification or add additional context in comments.

Comments

2

Try something like this:

String url = "http://cvs-server.test.com:8001/svn/test"; SVNURL svnUrl = SVNURL.parseURIEncoded(url); SVNRepository repos = SVNRepositoryFactory.create(svnUrl); ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(DEFAULT_USER, DEFAULT_PASS); repos.setAuthenticationManager(authManager); SVNNodeKind nodeKind = repos.checkPath("", repos.getLatestRevision()); 

nodeKind will be one of FILE, DIR or NONE.

8 Comments

why don't you need to specified the username and password ?
You have to... but that was not your question. I was assuming you know SVNKIT so far.
Why did I get none even the url is a svn file? Is it a bug ?
Please read the JavaDoc of SVNNodeKind
call checkPath with /test not with http://cvs-server.test.com:8001/svn/test like in my answer mentioned.
|
0

This is the correct way to do it:

public static boolean isFolder(String url) throws SVNException { SVNURL svnURL = SVNURL.parseURIEncoded(url); SVNRepository repos = SVNRepositoryFactory.create(svnURL); ISVNAuthenticationManager authManager = SVNWCUtil.createDefaultAuthenticationManager(DEFAULT_USER, DEFAULT_PASS); repos.setAuthenticationManager(authManager); SVNNodeKind nodeKind = repos.checkPath("", repos.getLatestRevision()); System.out.println(nodeKind); return nodeKind != null && nodeKind == SVNNodeKind.DIR; } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.