Tip of the Week Blog

Subversion Tip of the Week

An Apache Subversion working copy can be created quite simply by running the ‘svn checkout’ command. However, sometimes you’ll want to have more control over the contents of your working copy; for example, when you’re working on a large project and only need to checkout a single directory.

In this post, we share two ways to get greater control over your checkout commands.

1. Checkout a particular revision

By default, Subversion performs a checkout of the HEAD revision, but in some instances you may wish to checkout a previous revision, for example when you’re recovering a file or directory that has been deleted in the HEAD revision.

To specify a revision other than HEAD, add the -r switch when performing your checkout:

svn checkout (URL) -r(revision number) (Location)

In this example, we are performing a checkout of the project as it existed at revision 10.

customizing working copy

2. Performing Shallow Checkouts

A standard Subversion checkout copies the entire directory, including every folder and file. This can be too time-consuming if you’re working on a large project, or too complicated if your project contains many different branches, tags and directories. If you don’t require a copy of your entire project, a ‘shallow checkout’ restricts the depth of the checkout by preventing Subversion from descending recursively through the repository.

To perform a shallow checkout, run the ‘svn checkout’ command with one of the following switches:

  • –depth immediates: checkout the target and any of its immediate file or children. This is useful if you don’t require any of the children’s contents.

  • –depth files: checkout the target and any of its immediate file children.

  • –depth empty: checkout the target only, without any of the files or children. This is useful when you’re working with a large project, but only require the contents of a single directory.

In this example we are performing a shallow checkout on a ‘bug fix branch’ located within the branches folder, and specifying that only the immediate file children should be included (–depth files):

customizing working copy 2

Looking for a cross-platform Subversion client? Get a free trial of SmartSVN Professional at www.smartsvn.com/download

Subversion Tip of the Week

Tagging and Branching with SmartSVN’s ‘Copy Within Repository’

SmartSVN’s ‘Copy Within Repository’ command allows users to perform pure repository copies, which is particularly useful for quickly creating tags and branches.

To create a repository copy within SmartSVN:

1) Open the ‘Modify’ menu and select ‘Copy within Repository’.

2) From the ‘Copy From’ dropdown menu, select the repository where the source resides.

3) In the ‘Copy From’ textbox, specify the directory being copied. In ‘Source Revision,’ tell SmartSVN whether it should copy the HEAD revision (this is selected by default) or a different revision. Use the ‘Browse’ button if you need more information about the contents of the different directories and/or revisions that make up your project.

copy within repo

4) Select either:

  • Copy To – source is copied into the ‘Directory’ under the filename specified by ‘With Name’

  • Copy Contents Into – the contents of the source are copied directly into the ‘Directory’ under ‘With Name.’

5) Enter the copy’s destination in the ‘Directory’ textbox. You can view the available options by clicking the ‘Browse’ button.

6) Give your copy a name in the ‘With Name’ textbox.

7) The copy is performed directly in the repository, so you’ll need to enter an appropriate commit message.

8) Once you’re happy with the information you’ve entered, hit ‘Copy’ to create your new branch/tag.

Try SmartSVN Professional free today! Get a free trial at http://www.smartsvn.com/download.

Subversion Tip of the Week

SmartSVN’s Project Settings Menu 

SmartSVN’s ‘global preferences’ is a method of specifying settings across all your SmartSVN projects for efficiency and simplicity. However, sometimes you need to change settings for a single project, which is where the ‘Project Settings’ menu comes in handy.

In this week’s tip, we’ll look at some of the SmartSVN settings you can apply using this menu.

Accessing Project Settings

To access SmartSVN’s Project Settings, open the ‘Project’ menu and select ‘Settings.’ The different options are listed on the dialog box’s left-hand side.

project settings

1) Text File Encoding

This affects how file contents are presented. Choose from:

  • Use system’s default encoding – SmartSVN uses the system’s encoding when displaying files. This is the default setting for SmartSVN.

  • Use the following encoding – Select your own encoding from the dropdown menu. This is useful if you’re dealing with international characters, which may otherwise be encoded incorrectly.

Note, if you’ve specified a file type using the MIME-Type property, SmartSVN will choose this over the text file encoding settings.

2) Refresh/Scan

SmartSVN can either scan the ‘whole project’ or the ‘root directory only’ when you open a project. In most instances, you’ll want to scan the entire project, but if you’re working with particularly large repositories, the ‘root directory only’ option can speed up this initial scan and avoid high memory consumption.

3) Working Copy

Clicking on ‘Working Copy’ presents you with several checkboxes:

working copy

  • (Re)set to Commit-Times after manipulating local files – tells SmartSVN to always use a local file’s internal Apache Subversion property commit-time. This is useful for ensuring consistency across timezones, and between clients and the Subversion repository.

  • Apply auto-props from SVN ‘config’ file to added files – tells SmartSVN to use the auto-props from the SVN ‘config’ file. With auto-props enabled, you can perform tasks such as automatically inserting keywords into text files and ensuring every file has EOLs that are consistent with the operating system. Not only are auto-props a time-saving feature, but they can help you avoid human error within your project.

  • Keep input files after merging (monitored merge) – tells SmartSVN to always keep the .aux files following a merge, even for non-conflicting files. These files are stored in the ‘merged’ state and can be used to gain a deeper insight into what has changed during the merge.

4) Locks

Apache Subversion is built around a ‘copy-modify-merge’ model, but there are times when a ‘lock-modify-unlock’ model may be appropriate, for example when you’re working on image files, which cannot easily be merged. SmartSVN has full support for locking and unlocking files, but if you’re going to make heavy use of locks, you can configure SmartSVN to automatically flag certain files as requiring locking before anyone begins working on them. This is a useful reminder, especially if your project contains multiple non-mergeable files. Open the ‘Lock’ section of the Project Settings dialog and select either ‘all binary files’ or ‘every file,’ if required. The default is ‘no file.’

You can also choose whether SmartSVN should suggest releasing or keeping locks whenever you perform a commit, which is a helpful reminder if your team are working with multiple locks. Finally, the ‘Automatically scan for locks’ option tells SmartSVN to scan for locked files at specified intervals.

Find out more about locks by reading our ‘Locking and Unlocking in SmartSVN’ blog post.

5) Conflicts

When SmartSVN encounters conflicts, it adds new extensions to the conflicting files to help distinguish between them. By default, SmartSVN will take its cues from the config file, but if you want to specify particular extensions, you can select ‘Use following extensions’ and type the desired extensions into the textbox.

Remember, you can download your free edition of SmartSVN Professional at www.smartsvn.com/download

Subversion Tip of the Week

Apache Subversion supports the creation and use of ‘patches’ – text files containing the differences between two files. Patches specify which lines have been removed, added and changed, and are particularly useful when you don’t have write access to a repository. In these instances, you can create a patch file showing the changes between a file as it exists in the repository, and the version in your working copy. Then, you can create a ticket and attach your patch file for someone with repository write access to review and commit the accepted changes to the repository.

To create a patch file, you first need to review the differences between the specific files/revisions you are targeting using the ‘svn diff’ command. In this example, we are examining the differences between the version of the project in our working copy and the central repository.

tip of the week

If you’re satisfied with the differences ‘svn diff’ has identified, run the following command to create a patch:

svn diff > patch_name.diff

tip of the week 2

All the changes will now be written to a patch on your local machine.

tip of the week 3

You can now send this patch to a user who does have write access to the repository.

Creating a Patch Between Revisions

Alternatively, if you want to create a patch containing the differences between two revisions, run the following command:

svn diff r:(revision)(revision) (working-copy-location)

Followed by:

svn diff > patch_name.diff

Again, this patch file can now be submitted to someone with write access.

Want more advice on your Apache Subversion installation? We have a full series of SVN refcards for free download, covering hot topics such as branching and merging, and best practices. You can find out more at www.wandisco.com/svnref

Subversion Tip of the Week

SVN Revert

Apache Subversion’s ‘svn revert’ command allows you to discard local changes on a file or directory and replace it with the version in the repository. This saves you the overhead of performing a fresh checkout, and is also helpful when you need to quickly resolve a conflict.

To revert the changes on a single file, run the ‘svn revert’ command followed by the file path:

svn revert (working-copy)/filename

svn revert

It’s also possible to revert all the changes within an entire directory using the –depth=infinity switch. When this switch is added, any files that have been changed within the specified directory are replaced with their repository equivalent:

svn revert –depth=infinity (working-copy)

svn revert infinity

Useful Additional Commands

  • svn status

Before discarding your local changes, you may want to review exactly which files have been altered at the working copy level by using the ‘svn status’ command:

svn status (working-copy-path)

svn status

  • svn diff

The ‘svn diff’ command prints all the changes that have been made to human-readable files within the working copy, which is useful for identifying the file(s) you want to revert. Each line is prefixed by a character representing the nature of the change:

  1. + Line was added
  2. – Line was deleted
  3. A blank space represents no change

To run ‘svn diff’ enter the following command:

svn diff (working-copy-path)

svn diff

Looking for an easy-to-use cross platform Subversion client? Claim your free 30 day trial of SmartSVN Professional by visiting: www.smartsvn.com/download

 

 

Subversion Tip of the Week

SVN Blame

In certain situations, you may need more information about how a file changed in a particular Apache Subversion revision and crucially, who was responsible for that change. This is achieved by running the ‘svn blame’ command. This command prints each modified line of the specified file, alongside the revision number and the username of the person responsible for that change.

To run the ‘svn blame’ command, enter:

svn blame (repository-URL)/file

svn blame

However, sometimes the change may simply be an arbitrary whitespace or other formatting change. If you suspect this could be the case, the extensions switch (-x) can be used in conjunction with several other switches to filter out arbitrary changes:

  • –ignore-all-space (-w) – ignores all whitespace.
  • –ignore-space-change (-b) – ignores all changes in the amount of whitespace.
  • –ignore-eol-style – ignores changes in end-of-line-style.

In this example, we’re running ‘svn blame’ on the same file, but this time specifying that any EOL changes should be ignored.

svn blame -x –ignore-eol-style (repository-URL)/file

svn blame 2

Looking for an easy-to-use cross platform Subversion client? Claim your free 30 day trial of SmartSVN Professional by visiting: www.smartsvn.com/download

Subversion Tip of the Week

SVN Import

There are two main options when you need to add new file(s) to your Apache Subversion project: the ‘SVN Add’ command and ‘SVN Import.’ The advantage of performing an ‘SVN Import’ is that:

  • ‘SVN Import’ communicates directly with the repository, so no working copy or checkout is required.
  • Your files are immediately committed to the repository, and are therefore available to the rest of the team.
  • Intermediate directories that don’t already exist in the repository are automatically created without the need for additional switches.

‘SVN Import’ is typically used when you have a local file tree that’s being added to your Subversion project. Run the following to add a file/file tree to your repository:

svn import -m “log message” (local file/file tree path) (repository-URL)

In this example, we’re adding the contents of the “Release2” folder to the repository, in an existing ‘branches’ directory.

svn import 1

As already mentioned, intermediate directories do not need to exist prior to running the ‘SVN Import’ command. In this example, we’re again importing the contents of ‘Release2,’ but this time we’re simultaneously creating a ‘Release2’ directory to contain the files.

svn import create new folder

If you check the repository, you’ll see a new ‘Release2’ directory has been created. The contents of your ‘Release2’ file tree are located inside.

ubersvn import

Want more advice on your Apache Subversion installation? We have a full series of SVN refcards for free download, covering hot topics such as branching and merging, and best practices. You can find out more at www.wandisco.com/svnref

Subversion Tip of the Week

Getting Help With Your Subversion Working Copy

When it comes to getting some extra help with your Apache Subversion installation, you will find plenty of documentation online and even a dedicated forum where SVN users can post their questions and answer others. However, Subversion also comes with some handy built-in commands that can show you specific information about your working copy, files, directories, and all of Subversion’s subcommands and switches. This post explains how to access all of this information from the command line.

1) SVN Help

One of the most useful features of command line Subversion is the instant access to its built-in documentation through the ‘svn help’ command. To review all of the details about a particular subcommand, run:

svn help (subcommand)

In the example below, we’ve requested information on the ‘unlock’ subcommand. The printout includes all the additional switches that can be used in conjunction with ‘svn unlock.’

svn help unlock

Alternatively, if you need to see a list of all the available subcommands, simply run ‘svn help.’

svn help

2) SVN Info

If you need more information about the paths in a particular working copy, run the ‘svn info’ command. This will display:

  • Path
  • Repository URL
  • Repository Root
  • Repository UUID
  • Current revision number
  • Node Kind
  • Schedule
  • Information on the last change that occurred (author, revision number, date)

svn info

3) SVN Status

This command prints the status of your files and directories in your local working copy:

svn status (working-copy-path)

svn status

Want more advice on your Apache Subversion installation? We have a full series of SVN refcards for free download, covering hot topics such as branching and merging, and best practices. You can find out more at www.wandisco.com/svnref

 

Subversion Tip of the Week

Creating a New Directory in Apache Subversion

There are two ways to create a new directory in Apache Subversion. You can either create the directory in your working copy and then commit it to the repository as a separate operation, or simply create the new directory in the central repository.

1) Creating a directory in the working copy:

svn mkdir (working-copy-location/name-of-new-directory)

In this example, we’re creating a new directory called ‘Release2’ in the branches folder. You’ll need to perform a commit to send this new directory to the repository and share it with the rest of the team.

mkdir working copy

2) Creating a directory in the repository:

svn mkdir -m “log message” (repository-URL/name-of-new-directory)

mkdir url

3) The –parents Option

Note that regardless of whether you’re creating a new directory in the repository or in a working copy, the intermediate directories must already exist. If you need to create the  intermediate directories, you must use the –parents option.

In this example, we’re creating two directories in the ‘NewRepo’ repositories, a ‘Releases’ directory and a ‘Release3’ directory.

svn mkdir with parent switch

Looking for an easy-to-use cross platform Subversion client? Claim your free 30 day trial of SmartSVN Professional by visiting: www.smartsvn.com/download

Subversion Tip of the Week

Intro to the ‘svnversion’ Command

If you need to discover the revision number (or revision range, if working with mixed revisions) of your Apache Subversion working copy, you can use the svnversion command. This is particularly useful if your working copy contains mixed revisions, and you want to find out the range of revisions currently in your working copy. Run this command, followed by the location of your working copy:

svnversion (working copy path)

This will print either a single revision number or the revision range. In this example, the working copy contains files at revision 31 and revision 32:

svnrevision

Additional Useful Options

1) –no-newline

Removes the usual newline from the printed output.

svnversion –n (working copy path)

2) –committed

Lists the highest locally available revisions.

svnversion –c (working copy path)

3) –version

Prints the version of svnversion you’re using, and additional information such as compile date and copyright disclaimers.

svnversion –version

svnversion version

Looking for an easy-to-use cross platform Subversion client? Claim your free 30 day trial of SmartSVN Professional by visiting: www.smartsvn.com/download