Coding Horror: Setting up Subversion on Windows
Total Page:16
File Type:pdf, Size:1020Kb
Coding Horror: Setting up Subversion on Windows http://www.codinghorror.com/blog/2008/04/setting-up-subversion... programming and human factors by Jeff Atwood * Apr 5, 2008 Seng up Subversion on Windows When it comes to readily available, free source control, I don't think you can do beer than Subversion at the moment. I'm not necessarily advocang Subversion; there are plenty of other great source control systems out there ‐‐ but few can match the ubiquity and relave simplicity of Subversion. Beyond that, source control is source control, as long as you're not using Visual SourceSafe . And did I menon that Subversion is ... free? Allow me to illustrate how straighorward it is to get a small Subversion server and client going on Windows . It'll take all of 30 minutes, tops, I promise. And that's assuming you read slowly. The first thing we'll do is download the latest Subversion Windows binary installer . At the me of wring, that's 1.46. I recommend overriding the default install path and going with something shorter: c:\svn\ Note that the installer adds c:\svn\bin to your path, so you can launch a command prompt and start working with it immediately. Let's create our first source repository, which is effecvely a system path. svnadmin create "c:\svn\repository" Within that newly created folder, uncomment the following lines in the conf/svnserve.conf file by removing the pound character from the start of each line: anon-access = none auth-access = write password-db = passwd Next, add some users to the conf/passwd file. You can uncomment the default harry and sally users to play with, or add your own: harry = harryssecret sally = sallyssecret As of Subversion 1.4, you can easily install Subversion as a Windows service , so it's always available. Just issue the following command: sc create svnserver binpath= "c:\svn\bin\svnserve.exe --service -r c:\svn\repository displayname= "Subversion" depend= Tcpip start= auto It's set to auto‐start so it will start up automacally when the server is rebooted, but it's not running yet. Let's fix that: net start svnserver 1 of 33 27/07/2011 12:30 Coding Horror: Setting up Subversion on Windows http://www.codinghorror.com/blog/2008/04/setting-up-subversion... Note that the service is running under the Local System account . Normally, this is OK, but if you plan to implement any Subversion hook scripts later, you may want to switch the service identy to an Administrator account with more permissions. This is easy enough to do through the tradional Windows services GUI. Now let's verify that things are working locally by adding a root‐level folder in source control for our new project, aptly named myproject . set SVN_EDITOR=c:\windows\system32\notepad.exe svn mkdir svn://localhost/myproject It's a lile weird when running locally on the server, as Subversion will pop up a copy of Notepad with a place for us to enter commit comments. Every good programmer always comments their source control acons, right? Enter whatever comment you like, then save and close Notepad. You'll be prompted for credenals at this point; ignore the prompt for Administrator credenals and press enter. Use the credenals you set up earlier in the conf/passwd file. If everything goes to plan, you should be rewarded with a "commied revision 1" message. 2 of 33 27/07/2011 12:30 Coding Horror: Setting up Subversion on Windows http://www.codinghorror.com/blog/2008/04/setting-up-subversion... svn mkdir svn://localhost/myproject Authentication realm: <svn://localhost:3690> Password for 'Administrator': [enter] Authentication realm: <svn://localhost:3690> Username: sally Password for 'sally': ************ Committed revision 1. Congratulaons! You just checked your first change into source control! We specified svn:// as the prefix to our source control path, which means we're using the nave Subversion protocol. The Subversion protocol operates on TCP port 3690 , so be sure to poke an appropriate hole in your server's firewall, otherwise clients won't be able to connect. Now that the server's good to go, let's turn our aenon to the client . Most people use TortoiseSVN to interact with Subversion. Download the latest 32‐bit or 64‐bit Windows client (1.4.8.12137 as of this wring) and install it. The installer will tell you to reboot, but you don't have to. Now create a project folder somewhere on your drive. I used c:\myproject . Tortoise isn't a program so much as a shell extension. To interact with it, you right click in Explorer. Once you've created the project folder, right click in it and select "SVN Checkout..." Type svn://servername/myproject/ for the repository URL and click OK. 3 of 33 27/07/2011 12:30 Coding Horror: Setting up Subversion on Windows http://www.codinghorror.com/blog/2008/04/setting-up-subversion... Tortoise now associates the c:\myproject folder with the svn://servername/myproject path in source control. Anything you do on your local filesystem path (well, most things‐‐ there are some edge condions that can get weird ) can be checked back in to source control. There's a standard convenon in Subversion to start with the "TTB folders" at the root of any project : Because Subversion uses regular directory copies for branching and tagging (see Chapter 4, Branching and Merging ), the Subversion community recommends that you choose a repository locaon for each project root ‐‐ the "top‐most" directory which contains data related to that project ‐‐ and then create three subdirectories beneath that root: trunk , meaning the directory under which the main project development occurs; branches , which is a directory in which to create various named branches of the main development line; tags , which is a collecon of tree snapshots that are created, and perhaps destroyed, but never changed. Of course, none of this means your developers will actually understand branching and merging , but as responsible Subversion users, let's dufully add the TTB folders to our project. Note that we can batch up as many changes as we want and check them all in atomically as one unit. Once we're done, right click the folder and select "SVN Commit..." 4 of 33 27/07/2011 12:30 Coding Horror: Setting up Subversion on Windows http://www.codinghorror.com/blog/2008/04/setting-up-subversion... In the commit dialog, indicate that yes, we do want to check in these files, and we always enter a checkin comment‐‐ right? right? You'll have to enter your server credenals here, but Tortoise will offer to conveniently cache them for you. Once the commit completes, note that the files show up in the shell with source control icon overlays: 5 of 33 27/07/2011 12:30 Coding Horror: Setting up Subversion on Windows http://www.codinghorror.com/blog/2008/04/setting-up-subversion... And now we're done. Well, almost. There are a few sengs in Tortoise you need to pay special aenon to. Right click and select "TortoiseSVN, Sengs". 1. See that hidden ".svn" folder? These folders are where Subversion puts its hidden metadata schmutz so it can keep track of what you're doing in the local filesystem and resolve those changes with the server. The default naming convenon of these folders unfortunately conflicts with some fundamental ASP.NET assumpons. If you're an ASP.NET 1.x developer, you need to switch the hidden folders from ".svn" to "_svn" format , which is on the General opons page. This hack is no longer necessary in ASP.NET 2.0 or newer . 2. I'll never understand why, but by default, Tortoise tries to apply source control overlays across every single folder and drive on your system . This can lead to some odd, frustrang file locking problems . Much beer to let Tortoise know that it should only work its shell magic on specific folders. Set this via "Icon Overlays"; look for the exclude and include paths. I set the exclude path to everything, and the include path to only my project folder(s). Unfortunately, since Tortoise is a shell extension, seng changes may mean you need to reboot. You can try terminang and restarng explorer.exe, but I've had mixed results with that. And with that, we're done. You've successfully set up a Subversion server and client . A modern client‐ server source control system inside 30 minutes ‐‐ not bad at all. As usual, this is only intended as the gentlest of introducons; I encourage you to check out the excellent Subversion documentaon for more depth. I find Subversion to be an excellent, modern source control system. Any minor deficiencies it has (and there are a few, to be clear) are more than made up by its ubiquity, relave simplicity, and robust community support. In the interests of equal me, however, I should menon that some influenal developers ‐‐ most notably Linus Torvalds ‐‐ hate Subversion and view it as an actual evil . There's an emerging class of distributed revision control that could eventually supercede exisng all the centralized source control systems like Subversion, Vault, Team System, and Perforce. I'm skepcal. I've met precious few developers that really understood the versioning concepts in the simple 6 of 33 27/07/2011 12:30 Coding Horror: Setting up Subversion on Windows http://www.codinghorror.com/blog/2008/04/setting-up-subversion... centralized source control model. I have only the vaguest of hopes that these developers will be able to wrap their brains around the vastly more complicated and powerful model of distributed source control.