Svn usage (2): svn usage

Source: Internet
Author: User
Tags subversion client svn client svn update tortoisesvn

Svn usage (2): svn usage

This article describes how to use svn hooks and how to install and configure svn. (1)

We can see the hooks folder under the repository folder created by svn.
This stores the script files that the svn operations will execute at the same time.
(You can view each script file by yourself. The file has an introduction in English, including functions, parameters, and returned values.
I am not good at translation, so I should use other online materials for explanation --! )
1. Notifications of start-commit start submission
Input parameters: the command line parameters passed to your hook program. The order is as follows:
1. Version LIBRARY PATH
2. authenticated user name for submission
It runs before the transaction is committed. It is usually used to determine whether a user has the right to commit. 0 indicates that the authentication is successful.
2. pre-commit reminder before submission ends
Input parameters: the command line parameters passed to your hook program. The order is:
1. Version LIBRARY PATH
2. Name of the transaction to be submitted
Run before the transaction is committed. This hook is usually used to protect the content or location (for example, you require that all commits to a specific branch must include a bug tracking ticket number, or, the log information must not be empty) and cannot be submitted. If no error is returned, 0 is returned.
 
3. Notification of successful submission of post-commit
The command line parameters passed to your hook program in the order:
1. Version LIBRARY PATH
2. Submit the created revision number
It runs after the transaction is complete and creates a new revision. The program Exits normally without any errors.
 
4. pre-revprop-change version Attribute Modification
Because the attributes of the Subversion revision are not versionized, modifications to these attributes (for example, submitting the log attribute svn: log) will permanently overwrite the previous attribute values. Because data may be lost here, Subversion provides this hook (and the corresponding post-revprop-change), so the version database administrator can use some external methods to record changes. To prevent the loss of unversionalized attribute data, the Subversion client cannot remotely modify the attribute of the revision, unless this hook is implemented for your version library.
5. modify attributes of post-revprop-change versions
This hook corresponds to pre-revprop-change. In fact, this script is executed only when pre-revprop-change exists due to the suspect. When both hooks exist, post-revprop-change runs after the attributes of the revision are changed. It is usually used to send emails containing the new attributes. The version library passes four parameters to the hook: The Path to the version library, the revision of the attribute, the verified username that changes, and the name of the attribute itself.

The simplest way to use these hooks is
Copy a script, remove the. tmpl extension, and then customize the content of the hook to make sure the script is runable.
PS: Make sure that the hook script is executable. And the name is the name after removing. tmpl.
In addition, you must grant permissions to the SVN hooks and use the account that runs SVN to execute these hooks.
(If not, an error is prompted. The error code is 255. You can try other errors on your own ..)
What I want to do is to automatically synchronize the server (in the test environment) after the user commit to perform the update operation.
Here, I have one web server and one svn server. (For remote web servers
First use the ssh command to log on
)
The hook we need to use is post-commit.
We can use the command
Cp post-commit.tmpl post-commit.tmpl.bak
Music post-commit.tmpl post-commit
(Don't forget to set chmod to executable)
Chmod 755 post-commit
Vi post-commit
Here we can do a test first.
Add a line at the end of the file
/Bin/echo "commit">/tmp/commit. out
Then execute the commit operation to check whether the word commit. out exists.
Write our script and add the command at the end of the post-commit file.
/Usr/bin/svn update/www/project -- username m0sh1 -- password m0sh1
PS: the absolute path must be added here, and the project path after the update is checkout.
Svn: Can't convert string from native encoding to 'utf-8'
Add a command line
Export lang = en_US.UTF-8
In this case, go to the working directory and check whether the update is correct ..

For another example, many developers tend to ignore the submitted log information (or accidentally) for the sake of speed, so we can use the pre-commit script
To limit the submission of log information:
REPOS = "$1"
TXN = "$2"

# Make sure that the log message contains some text.
SVNLOOK =/usr/bin/svnlook
$ SVNLOOK log-t "$ TXN" "$ REPOS" | \
Grep "[a-zA-Z0-9]">/dev/null | exit 1

# Check that the author of this commit has the rights to perform
# The commit on the files and directories being modified.
Commit-access-control.pl "$ REPOS" "$ TXN" commit-access-control.cfg | exit 1

# All checks passed, so allow the commit.
Exit 0
(The above content is directly the content in the pre-commit script. You only need to grant the pre-commit executable permission .)
Then we can use this class to launch other functions that we want to implement.













How to Use svn

Svn (subversion) is a version management tool that has emerged in recent years and is the successor of cvs. Currently, most open-source software uses svn as the code version management software. How to quickly create a Subversion server and use it in projects is a major concern for everyone. Compared with CVS, Subversion has more options and is easier, several commands can be used to create a server environment,

This article is the fastest tutorial using Subversion. It helps you establish a set of available server environments in the shortest time, and can be applied to actual projects with just a slight adjustment.
This tutorial is divided into the following parts. For ease of instruction, it is used in windows to facilitate the use of projects with limited resources. In a UNIX environment, the installation method is different, and the command execution is not much different.

Tools/Raw Materials
Subversion server program installation package

Subversion Windows client TortoiseSVN installation package

Method/step
1. Software Download

<1> download the Subversion server program

Download the binary installation file from the official website, download the Binary Package, find Windows NT, 2000, XP and 2003, and then select Apache 2.0 or Apache 2.2, so we can see a lot of download content, currently you can download Setup-Subversion-1.7.12.msi.

<2> download the Subversion of the Windows client TortoiseSVN.

TortoiseSVN is a tool that extends Windows Shell and can be seen as a plug-in for Windows resource manager. After installation, Windows can identify the working directory of Subversion.
The official website is TortoiseSVN, the Download method is similar to the svn server in front, in the Download page we can choose to Download the version, the current maximum stable version of the installation file for the TortoiseSVN-1.5.5.14361-win32-svn-1.5.4.msi.

2 SVN server and client Installation

<1>, install Subversion, directly run the Setup-Subversion-1.5.3.msi, as prompted to install, so that we have a set of servers can run the environment.

<2>, install TortoiseSVN, also directly run the TortoiseSVN-1.5.5.14361-win32-svn-1.5.4.msi according to the prompts to install, but after the completion of the last prompt whether to restart, in fact, restart is just to make svn work copy in the windows special style effective, it has nothing to do with all the actual functions. In order to immediately see the good results, restart the machine.

<3> install the svn client program. You can also install the svn Language Pack if necessary. Note that the Language Pack version must be the same as that of the client program.

3. Create a version Library (Repository)

To run the Subversion server, you must first create a version Library (Repository), which can be seen as a database for storing data on the server. After the Subversion server is installed, you can run it directly, for example:

Svnadmin create E: \ svndemo \ repository

A version library is created under the directory E: \ svndemo \ repository.

We can also use TortoiseSVN to perform this step graphically:
Right-click the directory E: \ svndemo \ repository and choose TortoiseSVN> Create Repository here... ", then you can select the version library mode. Here you can use the default mode, and then create a series of directories ...... remaining full text>

Detailed steps for using TortoiseSVN

TortoiseSVN is a SVN client. Below is a general usage of where I did not know where to copy it. I hope it will be useful to you:
5. Use of the Client
1. Checkout Repository
First, you need to check the Repository of the server,
The so-called Checkout is to obtain all the files stored in the Repository specified by the server.
The Checkout and Visual Source Safe Checkout have different meanings,
VSS Checkout refers to locking a file. If you have used VSS before,
Pay attention to this issue when learning Subversion.
The specific Checkout Method is as follows:
Create an empty directory on the client, for example, F: \ Project1.
Right-click the Directory and select SVN Checkout... from the pop-up menu ...,
Enter the address of the Repository you want to connect to in the URL of Repository text box,
This URL can be added as a browser.
For the Repository created in section 2 of this tutorial,
The URL should be "svn: // xxx/project1"
(Xxx can be the host name or IP address of the server ).
Click OK to bring up an authentication dialog box,
Enter the username and password set in section 3 of the tutorial.
Click OK to complete the Repository Checkout.
For example, if the server repositoryhas an a.txt file,
After Checkout, an a.txt file will be displayed in the directory F: \ project1.
In this example, because no files have been added to the Repository on the server,
Therefore, no file is Checkout in the F: \ Project1 of the client.
In addition to the files and directories stored in the Repository generated in F: \ Project1,
An implicit directory named ". svn" is also generated, which is managed by subversion,
Do not delete or manually change the files and directories.
Now the files and directories in F: \ Project1 are called the "Working Copy" abbreviation of "WC" in Repository"
(This short name is... Khan ).
Modify, add, and delete files and directories in Repository in the future,
All are implemented through the "Working Copy" operation.
After Checkout is executed,
A small status icon is attached to the icon in the lower left corner of the F: \ Project1 directory.
(When the file in the F: \ Project1 directory changes, the status icon also changes ),
It indicates that F: \ Project1 is a Repository "Working Copy ",
F: \ all files and directories in Project1 also have similar status icons.

2. Add a file
Copy the file or directory to be added to F: \ Project1,
Right-click the file or directory, choose TortoiseSVN-> Add, and click OK.
If more than one file or directory is added,
Do not place any files in the dot F: \ Project1,
Right-click TortoiseSVN-> Add,
You can add multiple files or directories.
The file status icon changes.
The Add command only tells the local "Working Copy" to include the file in version management,
The change is not submitted to the server,
If you want others to see your changes to Repository, you need
Right-click F: \ Project1, SVN Commit ...,
Complete the repairs you have made... the remaining full text>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.