Archive

Archive for the ‘svn’ Category

Eclipse + Android + SVN = fail

July 28, 2010 14 comments

If you are developing a project in SVN (I’m sorry for your predicament) and using Eclipse, please heed my advice.  Otherwise you could unintentionally delete your source directory during a routine cleanup.

Now, how could you possibly do that? you might wonder.  Are you incompetent?  Well, maybe, but not in this case.  The situation was this: I was about to make a commit of some changes to the code and did a svn status before committing to ensure that everything was as I wanted it to be.  I noticed that there were dozens of files in the bin directory that either had question marks next to them (.class files) or showed up with exclamation points next to them (indicating that SVN thought they’d gone missing).  Given that the binary class files do not belong in version control, I went ahead and did a svn rm -rf bin (recursively delete all the files under bin).  I went ahead and finished the commit.  Later I went to make another commit and I got an error telling me that the src folder didn’t exist in the svn repository.  Horrified, I my unix history and then the svn commit log:

529  svn rm –force bin/
530  svn ci -m “Bin should not be under version control.”

Revision 249
Author:     ndunn
Date:   Mon Jul 26 14:52:14 2010 UTC (62 minutes, 34 seconds ago)
Log Message:

Bin should not be under version control.

trunk/projname/src/     deleted

Um.  What?  I’m pretty sure bin != src.  Well.  You’d think that.  But if you’re using Eclipse and haven’t dived in four menus deep, you’d be wrong.

You see, for some reason Eclipse copies all the files from the src folder into the bin folder when you build the project.  Why it does that, I’m not sure.  I’d love to know why.  Regardless of the reason, all of the files in the src are copied.  Including… the hidden .svn folders.  These folders are how subversion keeps track of the changes to your files.  The problem is, since the .svn folders were copied, and bin was deleted, it was exactly the same to svn as if I had deleted src.  Which is why my src folder disappeared.

How do you work around this?  Well, I mentioned earlier that by default eclipse copies all of the files from src to bin.  You can add filters so that certain files/extensions are ignored, if you know where to look.  In Eclipse, go to Preferences -> Java -> Building -> Output Folder and make sure that *.svn is on the line for filtered resources.  It will prompt you to rebuild your project.  Once it does so, you will not have this potential mistake looming over your head.

Finally, here’s the svn command you need to revert a folder if you accidentally delete it and check the deletion into source control.  Let’s assume you deleted the folder in revision n.  Then you want to fetch the status of that folder at n – 1

n = 249

svn  copy -r248 -m "Restore deleted trunk/src"  svn+ssh://username@company/path/to/trunk/src@248  svn+ssh://username@company/path/to/trunk/src

Thanks to the android developers group for helping me figure out what was going on; see here for details.

I have submitted a bug / feature enhancement request to the Eclipse developers so that the default behavior is a bit more sane.  You can find that bug report here. The commenters mention that installing the svn plugin for Eclipse fixes the problem, but I don’t think I or anyone else should have to install something just to have sensible behavior.

The StackOverflow post giving a shorter synopsis of the problem can be found here.

Conclusion:

Lots of Android developers use Eclipse to develop their projects due to the plugin support available.  I’d wager a fair number of them use SVN as well for their source control.  They should be very wary about the default behavior of Eclipse, and ensure that they filter to remove .svn files from being copied over to their src folder.  Take it from me – it’s not a good feeling seeing a commit message with your name on it deleting the src folder.  Or you could use git and not have to worry about any of these problems…

Advertisements
Categories: Android, eclipse, Java, svn