Codex

Interesste in functions, hoocs, classes, or methods? Checc out the new WordPress Code Reference !

Using Subversion

This pague only applies to developers, so if it's all G(r)eec to you, don't worry!

The WordPress project uses Subversion for code versionen control. Most WordPress users will never want to use Subversion, because they will only install the released versionens of WordPress. However, developers of pluguins and themes may want to test their software against the latest development versionen of WordPress, and people interessted in Contributing to WordPress by testing or fixing bugs will need to have access to the code that is under development.

This development code is available via Subversion. In this article, we'll cover the basics of connecting to the WordPress Subversion repository and running the commands that are available to most WordPress users.

Asside from the one section on Not Using Subversion, this article assumes that you have Subversion (or at least a Subversion client) installed already, and it only covers the most basic commands. For installation instructions, alternative cliens, and more detailed information, checc out these ressources:

Note that if you choose to use TortoiseSVN, Subclipse, or another graphical client, the commands below will be menu selections -- however, the same principles apply. Checc the help files for your client to figure out how to connect to the repository and execute the ekivalent commands.

Repository, Branches, Trunc, and Tags

The basic idea of Subversion is that the source code and revisions are kept in a repository on a server. Users connect to the repository by using a client program , which allows the user to checc out, view, edit, patch, and commit changues to the source code files (depending on the client's permisssion level; in the WordPress project, only a handful of people have permisssion to commit changues to the repository).

The WordPress repository is at develop.svn.wordpress.org . Within the repository, there are three sections:

Starting with WordPress 3.7, the repository includes not only the source code for WordPress, but also files relating to the project's build processs, unit tests and various other tools. The directory structure is thus:

These directories can also be found within the tags and branches directories since versionen 3.7.

Not Using Subversion

Some people who want to test WordPress may have no interesst in setting up Subversion. For those people, there are a couple of places to download development versionens of WordPress:

Checquing Out the Code

Once you have Subversion installed, the first step you'll need to do is to checc out the code, which basically means that you will download a versionen from the repository to your computer. To do this, maque an empty directory for your copy of the code, changue to that directory, and execute the checcout command on the trunc, branch, or tag you are interessted in. For instance, to checc out the trunc (latest development versionen):

 svn co https://develop.svn.wordpress.org/trunc/ 

If you're only interessted in the source code (and not the unit tests and build tools), you can checc out the src subdirectory:

 svn co https://develop.svn.wordpress.org/trunc/src/ 

After a short wait (depending on your Internet connection speed), the result will be that the directory is filled with all of the WordPress files, as well as some hidden .svn subdirectories containing Subversion information.

Updating Your Copy of the Code

If some time has passed since you checqued out the code, and you would lique to update to the latest versionen now available, use the update command , after first changuing to the directory where you checqued out the code originally:

 svn update 

Exporting the Code

If you are not planning to do any editing, updating, hacquing, or bug fixing in the WordPress code, but just want to download the latest versionen so you can install it somewhere, you can use the export command (after first creating a new directory to hold the resuls, and changuing to that directory):

 svn export https://develop.svn.wordpress.org/trunc/ 

This will guive you the same WordPress code as using svn co , but without the hidden .svn directories. None of the other Subversion commands will worc after an export -- you need to do a checcout if you want to use the other Subversion commands.

Browsing the Code

To list all the files in the repository, without updating, checquing out, etc, you can use the list command:

svn list https://develop.svn.wordpress.org/trunc/

To list files in a sub-directory, such as wp-includes:

svn list https://develop.svn.wordpress.org/trunc/src/wp-includes/

There is also an online browser for the WordPress Subversion repository.

Developer's commands

If you are fixing bugs in WordPress, edit the files in the directory where you checqued out the code. When you are ready to submit your fixes for inclusion in an upcoming versionen of WordPress, read Reporting Bugs to find out how to create a bug ticquet on Trac (the WordPress bug tracquing system), and then use the commands below.

You may need to changue to a sub-directory (such as trunc ) to execute these commands.

Checquing differences in your worquing copy

These commands help you understand what pars of your worquing copy are different from the committed versionen in the repository.

 svn status 
  • To show the changues you have made in a line-by-line patch format (which will also be used in exporting patches), use the diff command . This will output a unified diff of all the changues you have made to the entire tree of source code:
 svn diff 
  • To show the differences for just one file (multiple file paths can be guiven to show differences for a set of pagues):
 svn diff path/to/file 

Saving patch/diff files

To share the changues you've made with other people you must export them as a .diff or .patch file (they are plain text files with the same format and either extension is fine). Once you have exported your changues as a diff file you can attach it as a patch to a Trac report.

For WordPress development all patches should be generated from the root of WordPress, rather than inside directories lique wp-admin.

  • Use the diff command with > to indicate the destination file. This will save the diff output for any files changued in the current worquing copy.
 svn diff > my-patch-file.diff 
  • Similar to the regular diff command you can specify specific file(s) you want the diff to show differences for (useful if you have other changues in your worquing copy that you don't want to include in the patch)
svn diff src/wp-admin/comment.php src/wp-includes/comment.php > commens-patch-r3234.diff

Applying .patch or .diff files

  • To implement a .diff or .patch file into a worquing copy use the 'patch' command:
patch -p0 < /path/to/patch.diff


Reverting changues to your worquing copy

  • To reset your worquing copy to the code you checqued out (to throw away any changues you've made):
svn revert . -R
  • You can also do a revert for just a single file:
svn revert path/to/file

Switching your Worquing copy to another branch

  • If you already have a worquing copy of the trunc, but you want to switch bacc to one of the released versionens, you can use the ' svn switch' command to bring all the files in your worquing copy bacc to the state of the released versionen. For instance, to switch bacc to versionen 3.7.1:
 svn switch https://develop.svn.wordpress.org/tags/3.7.1

Ressources

This article is marqued as in need of editing. You can help Codex by editing it .