How to rename Java packages without breaking Subversion history?

若如初见. 提交于 2019-12-03 23:18:18

Perhaps it's not practical for your exact needs but TortoiseSVN has a handy feature regarding renames. You could do this:

  1. Use your IDE's refactoring feature to rename stuff.
  2. Launch the "Check for modifications" dialogue from TortoiseSVN.
  3. For each renamed item, you'll see two entries: a missing "source.java" item and an unversioned "target.java" item. Highlight both and choose "Repair move" from the context menu.

Repair moves/renames

markusk

Have you considered using the Subclipse plugin? It may solve your problems, according to How do I use Eclipse Refactoring Tools and stay in sync with SVN through Subclipse?

Are you sure keeping history is NOT working if you are using the refactoring method included in eclipse?

With NetNeans I regularly change package names and the underlying 'svn plugin' will silently move the content (which saves history) into the new directory (after that the normal refactoring will happen).

so: Have you tried it from within eclipse if the history is kept with the subversion plugin? (e.g. in a fresh check-out copy to avoid failure)

At least you could use NetBeans to do this one-time task ...

Yes, it will work. You could install the command line version of svn and write a batch file that will do the svn stuff. Automating the eclipse stuff would be a bit more work, and probably not worth it unless you're already familiar with the eclipse API.

Test it with one package before you do everything just to make sure you're doing all the steps right.

You can do this, and it's not that hard - your best bet to get a clean SVN history is to do it in 2 steps (can become one commit) - though for good results I recommend using the CLI client.

  1. Use svn mv to move the folders/packages
  2. Go into Eclipse, or use grep from the CLI to fix the packages in the files to match the new name

Then you can commit as a change-set, and the history at the file level should match.

If you're using Maven or a packaging tool, recommend you run a release before doing something like this - also it's worth cutting a tag immediately before this in case you need to go back to the old structure

I discovered that the subclipse plugin gives the error message " is already under version control" when committing a class that has been moved to a new package (i.e. not under source control yet) and the parent of this package is also new.

When this happens, I can commit the changes using TortoiseSVN. After that I only need to refresh the project in Eclipse.

After moving a class to a new package whose parent is already under source control, subclipse can commit this change without problems.

Instead of renaming the packages you could do this:

  1. create the new package structure in your project. Once done your project should look something like this:

           com -
               |- myOLDcompname -
               |                |- feature1 -
               |                            |- classA.java
               |                            |- classB.java
               |- myNEWcompname -
                                |- feature1
    
  2. add the new folders under version control so svn can track them

  3. move your java classes from old packages to new ones. Eclipse should update all the classes imports and package declarations accordingly. Most importantly because old and new packages are under vcs this step should keep the history of the classes.
  4. when done delete the old folders
  5. commit!
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!