Recent exploration in the world of FOSS has helped me adopt SVN more easily than ever before. In this post, I will share some of my learnings about working with SVN using CLI and NetBeans.
Basically, I am going to map every possible command that were used on Command Line Interface (CLI), during past 2 weeks to the functionalities provided by Subversion Support in the NetBeans IDE (6.0+).
Using 6.7 RC2 for demonstration,
After making project and their respective copies in the SVN repository of my plug in at Kenai. I forgot to update the /trunk after I had fixed a bug that was affecting plugin’s version v1.0, which was fixed for version v1.1. Actually, I had earlier made a tag by copying the sources from “/tags/release60_base/plugin-code-base” to “/tags/release60_fixes/plugin-code-base”.
I started fixing the code in the tagged repository before renaming/moving the repos to “/branches/release60_fixes/plugin-code-base”. Then, I realized that I had not merged the changes to the /trunk, which was required. So, we will see in the rest of this blog, how to do the merge using CLI and NetBeans IDE.
Using Command Line Interface
Now, I need the working copy of the code kept at /trunk, so I have to do a checkout, first.
svn checkout URL
You can learn more about the checkout from the book of Version Control with Subversion. I have substituted URL with https://kenai.com/svn/nbrcp-kolektiv~incubator/nbplugins/branches/release60_fixes in the above, as well as the following command(s).
Now, having read the common use-cases of Merging Whole Branch to Another in the book, I decided to give it a try using CLI. So, I did the following;
svn log --stop-on-copy URL
Here’s what the book states;
The log subcommand will normally show every change ever made to the branch, including tracing back through the copy which created the branch. So normally, you’ll see history from the trunk as well. The --stop-on-copy will halt log output as soon as svn log detects that its target was copied or renamed.
Now, this presents the required textual information, and I found out that copy was made in revision r25 and last commit was made in revision r32. Now, we know where the changes took place since making the copy of trunk in r25. As per the book, I used the following command to do the merge;
svn merge -r 25:32 URL
Firstly, change the directory to the working copy and if we use svn merge, it assumes that current directory is the working copy. So, it will apply changes that happened between r25-r32 to the working copy. It may happen that there might be some conflicts, which you can resolve from command line. Now, use the following to see the status and detect any conflicts of the working copy after merging has been done;
The console output shows only modifications (denoted by M), addition (denoted by A)/deletion (denoted by D) or conflicts (denoted by C). If there are any conflicts, they are required to be resolved. So, please refer this guide on how to resolve the conflicts using CLI. Once they are resolved, you should commit the changes to the server (/trunk).
svn commit -m some_message
where some_message = “Merged changes r25:32 into the trunk..”
Hit Enter button to send the changes to the server. The book states,
Again, notice that the commit log message very specifically mentions the range of changes that was merged into the trunk. Always remember to do this, because it’s critical information you’ll need later on.
Using NetBeans IDE
Now, I will show you how to do the same using NetBeans IDE to increase productivity, without worrying about typing issues that may occur using CLI. Also, changing directories, retrieving logs, doing manual merge, etc.
All of these may go easily wrong.. Although, its good to know how to work using CLI. Its much better to use IDE’s for the same purpose. Thus, I have written this blog that may help you switch to NetBeans IDE for the same.
Firstly, goto Team | Subversion menu and select Checkout… This will open a wizard where you will enter the URL, username and password. Now, refer this blog on how to checkout the code and configure it, as per the requirements. Once its done, project will be opened and displayed under Projects window.
Right-click the project node and select Subversion from the context menu. Then, select Merge Changes.. from the menu as displayed here;
Soon, following window opens that lets you configure the way you want the merge to happen and that too, in one step! Have a look;
You can see various options in the form of drop-down list and browse, search buttons. I willl brief you about the same as we move ahead. Drop-down list have three options to choose from;
Type I – One Repository Folder Since its Origin
Type II – One Repository Folder
Type III – Two Repository Folders
So, I selected Type II because I want to merge changes from single repository folder (/branches/release60_fixes) which is other than the working copy, synchronized with (/trunk). This preview is shown within the same window and can be viewed by scrolling down the same window.
Browse.. will let you choose the repository folder to merge from. We will choose /branches/release60_fixes/ahrefhyperlink.revamped (This folder might change in future, you may expand /branches as shown in the figure to observe changes taken place) for merge. Have a look;
At the beginning of this entry, I mentioned that one can find out that changes between which versions have to be merged in the working copy. To do that, one has to make use of svn log. In this case, one would just click the Search.. button and following window pop-up!
Clicking List will list all the changes that have occurred since the date entered in the shown field. As you can see tag was made in r25 and last code update took place in r32. So, we will first choose the revision #25 for Starting Revision and #32 as Ending Revision, one-by-one. See the following figure;
This works same as the svn merge command used earlier. Click Merge button to commence the merge operation. Once the merging is finished, one can see whether there are any conflicts or not.
Conflicts may occur, when the HEAD revision of the /trunk repository is not in sync with the other repository, when sources were first copied from /trunk. See the following figure, I got two file conflicts;
For resolving conflicts, you may refer this guide written by Sun Technical Writers. Once conflicts are resolved, you must now commit the sources with this message as recommended earlier, “Merged changes r25:32 into the trunk”. That’s all for the day. Hope this helps you get started effectively.