views:

31

answers:

2

I am developing a java based eclipse plugin that monitors file activity. I need to find out if a given file is checked into the SVN by the user.

edit

There are two files. Local file and repository. I have to keep track of the local file and make sure the user commits it to the repository every time he saves it locally.

A: 

If it's anything like the SVN we use at my work, you can't. The only thing there is is "Latest Version" which was the last time it was committed. Are you asking about knowing when a file is added to the repository?

XstreamINsanity
Changes made to the local file must be committed to the svn repository. I want to warn the user to commit it in case he forgets.
Karthik Kottapalli
So at the end of the day, it tells the user "Hey, your file is different than that in the repository. Is is 'committable?'" You wouldn't want them to commit a file that doesn't work, so you'd have to give them the option to say no. Is this what you're looking for?
XstreamINsanity
Also, I don't know if this will work with the SVN you have, but to go along with what adamnfish gave you, this link explains what some of the returns may be: http://svnbook.red-bean.com/en/1.0/re26.html
XstreamINsanity
I am using Google Host SVN. The user must commit immediately for the first 20 commits, even if it is not committable. After the 20 commits, the program will understand that the user is mature enough to decide on his own.
Karthik Kottapalli
Eeeek, be careful of that. I don't know what programs they are working on, but if someone needs to add something like a spinning zoom effect to an item after it's been selected and they just started with the company, you might not want them to commit for some time. :) But I get what you're saying.
XstreamINsanity
+2  A: 

You could make svn do the work for you by running svn status /path/to/my/file from the shell on the path to the file. If it isn't checked in then you will get ? /path/to/my/file back (it begins with a question mark). If it is checked in and unmodified you will get no response from svn status, otherwise the line will begin with the character describing the file's status (eg. A, M, D).

Bear in mind if the file is not within an svn repository svn status will throw a warning svn: warning: '/path/to/my/file' is not a working copy.

[edit] Having seen your clarification, you need to check for all the status flags (added, modified, deleted etc.) and remind your user to commit where appropriate. svn help status contains the (exhaustive) full list.

If you run svn status from within the project without providing a path it gives you the status of all the files in the repository. If it is unmodified this will yield nothing, otherwise any changes will be printed to stdout. You probably want to do this, rather than running through each file to check its status.

adamnfish
Thanks for the tip, adam. I should be able to fix it now.
Karthik Kottapalli
If this helped you Karthik, you should upvote and accept the answer so Adam gets credit for giving you this advice.
Amir Afghani