Thursday, August 15, 2013

Refactor/rename package in Eclipse with Subclipse and SVN

Refactoring a package by giving it a new name can give quite annoying problems when trying to commit it from within Eclipse using the Subclipse plugin.

You can get (tree) conflicts, maybe even causing you to rollback all your changes and then step by step committing them.
Below is a set of steps you can follow that should not cause any problems if executed in this order :) In short: you do your refactor, then first commit only the deletions, and only then commit the additions (which are the moved files in their new package location).

Detailed steps

Set up and tested with: Eclipse Juno version, Subclipse plugin, SVN 1.6:

  1. Rightclick on your project and select Team --> Synchronize with Repository
  2. Select the incoming view
  3. Now note in the incoming view, it shows conflicts on some/most directories (packages) that were renamed. Just do an update on those.
  4. Go to the outgoing view
  5. If you now select all items with a '-' (the deleted ones) and then try to commit, you get an error on the commit: Tree remains in conflict. Notice the red/green icons on several directories (actually the ones that had a conflict in step 3), see screenshot:

    So those need to be resolved first.
  6. Right click on one of those entries (multiple select not supported for the Show Tree Conflicts operation) and select Team --> Show Tree Conflicts. That shows something like:

  7. Rightclick and select Resolve...
  8. On that next screen:

    select only Mark conflict resolved.
  9. Click Finish
  10. Now the entry is not marked red/green any more, and only shown with a '-' in the Synchronize screen! 
  11. Do that for all red/green arrows (conflicts)
  12. When done, right-click on all items marked with a '-' and select Commit. And that succeeds!
  13. Finally, commit now the ones marked with '+' (so the added ones)
  14. Really final step: note that sometimes some empty packages with the old name stay around. Deleting them in Eclipse and then trying to commit gives again conflicts(!). Those I just delete directly from the Repository perspective and do an update on those.
Bonus tip: sometimes when another team member has commited a new module, the Synchronize perspective will show the (compiled) /target dir and its items as needing to be committed. Even though the directory is already in the .svnignore file, since right-clicking on it won't allow you to add it. Solution: do an update on that target directory. After this it should be fine and it should not show up anymore on the next Synchronizes.

No comments: