This blog will help you “prevent” all the svn shit you and your team have been going thru.
– As a developer I care for coding, a tool is to help me make things easier. svn helps, but has its own pitfalls. I have managed to find a organized way of doing things that help me keep things clean.
– As a manager, I cant let my dev’s fall into the trap of svn issues.
You and me both know that a troublesome svn commit can kill your evening. Right ?
So I’ll try to explain and go into detail of every step explaining “why” too, but you dont have to understand why. Just follow the steps and you should be fine.
Create 3 directories (checkout, wip and bb)
wip stands for work in progress, you knew that.. didn’t u..
bb stands for buddy build
1) You use “svn checkout” to get your project from the svn server.
2) Now dont start work, copy these files to your “wip” directory. Do all that you want to here.
3) When you are ready to checkin, create a subdirectory in your bb directory. May be call it YYYYMMDD. In this directory create wip and checkout directory.
4) copy stuff from the wip directory to your bb/YYYYMMDD/wip directory
5) in your checkout directory, run a “svn update” so that you get the latest from svn
6) copy the project from your checkout directory to your bb/YYYYMMDD/checkout directory
7) Now, open a directory compare tool, meld, araxis merge or beyond compare. On the left keep your bb/YYYYMMDD/checkout directory and on the right keep you bb/YYYYMMDD/wip directory
8) Move only “files” from your right to left, DO NOT move directories. Delete files in your checkout directory if need be
9) Copy your bb/YYYYMMDD/checkout directory to your checkout directory and overwrite your checkout folder
10) Build the bb/YYYYMMDD/checkout directory to ensure that you dont mess up the build.
11) in your checkout directory do a ‘svn status’.
This is where the fun starts
For every ? do a svn add file/directory name
For every ! do a svn delete file/directory name
12) Do a ‘svn status’ again unless you get a M, A or a D against all the files (MAD). If you have a MAD, then you are ready for commit.
13) ‘svn commit -m “your message”‘. It will work :).
Now, why create so many directories.
– checkout is obvious, you want to get the latest and best from svn folder
– wip is obvious, you want to work somewhere, with no worries to get screwed by a svn update
– bb, is not obvious, a file/folder compare can screw up very easily. If you move a file from left to right instead of right to left, you are screwed. you can loose all your changes in your wip folder.
– why step 9, you ask, since you dont want to check in .class files and .obj files right ?
– why only copy files and NOT directories. Since svn maintains the state of your file/directories in a hidden folder .svn. If you copy directories, you can overwrite your checkout folder and mess things up.
More details for the people who want to know about the svn commands.
svn checkout – will check out the files from the project.
Here you will edit your source files, unit test to ensure that u have all covered. By now you have 3 things to worry about.
1) Someone else make checkins to the same project you are working on.
2) Someone made changes to your source files
3) You may break them, or they may break you.
svn status – will check the status of your files. Ideally you should just have a M, A or a D before each file name. M, meaning modified file, A meaning this file was added to your directory and D, meaning a file was deleted.
svn status -u – will do that sanity check for you. It will return a list of files with the result of the sanity test. The character denotes the status of the file you have checked out.
U means the server has a more later checkin of the file, from the last time you checkedout/updated the local working repository
G means that svn can automatically merge the files (the changes are in different parts of the source code)
C There are conflicts, same part of the code has been modified by a different dev on the svn server. This needs to be merged manually.
(CVS guys please note : cvs update does both status and update of svn, so get used to using status and update separately on svn).
For every file labelled C on the svn status output, 3 files will be created .mine (file before editing), .rold (file after editing), .rnew (updated file from svn server)
One more change is made, to your original source file. Markers are added to your orignial code to identify what code was yours and what has come from the svn server.
To Merge you have the following options
– Manually edit the source file, since you can search the markers, you can identify and play around with the code.
– Use a graphical tool like kdiff3 source.cpp.mine source.cpp.rnew -o source.cpp
– Use tkdiff -conflict source.cpp
– Junk the changes, you dont want changes from the svn server :), svn revert source.cpp
Hope I have kept it simple for you to understand and play round with.