Build a Repository and Working Copy
This article moves on from my previous two articles on Subversion, "Getting Started with Subversion on Windows" and "Five Steps to Further Success with Subversion." Those articles provide a grounding in Subversion. This article builds on that work by taking you into more advanced areas.
Let’s build a simple repository and a working copy. The steps are documented in my previous articles, so I just include them here for simplicity.
Create the repository:
- Create a folder containing your source code (for example, C:\myproject).
- Structure this folder so that it contains three subfolders: branches, tags, and trunk.
- Copy all source code folders and files into C:\myproject\trunk (for example, C:\myproject\trunk\guicode).
- Create a repository folder (for example, C:\svnrepo).
- Change the directory to C:\svnrepo.
- Run this command:
svnadmin create repo
- Change the directory to C:\myproject\trunk.
- Run this command:
svn import -m "Initial Import" . file:///c:/svnrepo/repo
Create the working copy:
- Change to any old work directory (for example, C:myworkdir).
- Check out the files in the repository with this command:
svn checkout file:///c:/svnrepo/repo
Figure 1 shows an excerpt from my C drive after running the above commands.
Figure 1 The repository and working copy.
Not too much of a surprise in Figure 1: We’ve got the source code tree in the folder called myproject. Typically, the source code tree will contain thousands of files and subfolders. This simple example includes only a single Java file from one of my earlier articles. Remember, if it works for one folder and one file, it will work for any number of them.
Inside the myproject\trunk folder is a subfolder called guicode. containing a single Java file called PaymentMachine.java (shown in the right pane in Figure 1). Notice the folder called .svn beside the file PaymentMachine.java. The .svn folder is a critical item in the context of Subversion—this folder is used by the Subversion client to tie the local files to the associated Subversion repository. For more on this key folder and its contents, see my earlier articles on Subversion.
The second main folder in Figure 1 is myworkdir. This folder represents what’s called the working copy in Subversion. This is the set of folders in which you make source code changes; in other words, your working copy of the repository files. We’ll look more closely at the contents of myworkdir, but for the moment just notice the green checkmarks on the subfolders myworkdir\repo and myworkdir\repo\guicode in Figure 1. These markings are provided by TortoiseSVN.
The last item of note in Figure 1 is the svnrepo folder. This is the source code repository. Normally, you’ll host the repository in some secure network location (rather than on the same disk as the local working copy). However, the key point here is that Subversion has no trouble using a local repository.
The basic setup is done. You’re ready to get up and running with TortoiseSVN!