SVN::Notify::Git - Keep a Git repository synchronized
Version 0.01
Through svnnotify in the post-commit hook:
svnnotify --repos-path "$1" --revision "$2" \
--handler Git \
--to "/path/to/git/repo" \
[--remote "name_of_remote_git_repo"] \
[--rewrite-author] \
[--svn-binary "/path/to/svn/executable"]
or, using SVN::Notify::Config:
#!/usr/bin/perl -MSVN::Notify::Config=$0 --- #YAML:1.0 '': PATH: "/bin:/usr/bin:/usr/local/bin" rewrite-author: 1 '/project1/trunk': handler: Git to: "/path/to/git/repo/project1" '/project2/trunk': handler: Git to: "/path/to/git/repo/project2" remote: "gitorious"
Keep a Git repository synchronized with (part of) a Subversion repository. The Git repository is supposed to be on the same machine as the Subversion repository. Optionally, this module can push the changes from the local Git repository to a remote Git repository.
NOTE: This module was created for one-way traffic. If the local Git repository is ever updated from any other source, this module will detect the changes and die. Some future version may (or may not) support two-way traffic.
Please keep in mind that this module is a work in progress, and that there is a reason why this module cannot be found at CPAN, yet.
If you are going to use the --rewrite-author parameter, you will need
to tell Subversion that the svn:author revision property may be changed.
You do this by creating a script called pre-revprop-change in the
hooks directory of your Subversion repository and making it
executable:
#!/bin/sh
repo="$1"
rev="$2"
user="$3"
prop="$4"
action="$5"
[ "${prop}" = "svn:author" -a "${action}" = "M" ] && exit 0
exit 1
(Unfortunately I can't give an example for non-POSIX systems, but the
idea is to allow Modification of the svn:author property.)
Before using this module, you should first create a Git repository to be synchronized. This repository should have write access for all users who execute the Subversion post-commit hook (if your users have access to the Subversion repository using SSH keys, there is probably only 1 user who will ever execute the post-commit hook).
If your Subversion repo has the standard layout of
/local/svn/
|- project1
| |- branches
| | \- ...
| |- tags
| | \- ...
| \- trunk
| \- ...
|- project2
| |- branches
| | \- ...
| |- tags
| | \- ...
| \- trunk
| \- ...
...
you can do this by executing the following:
# mkdir -p /local/git # git svn clone --stdlayout file:///local/svn/project1 /local/git/project1 # git svn clone --stdlayout file:///local/svn/project2 /local/git/project2
This will create 2 Git repositories: 1 for project1 and 1 for project2.
If the layout of your Subversion repository is different, check git-svn(1).
If you intend to have this module push the changes to a remote Git repository after the local Git repository has been updated, you will need to make the local Git repository aware of the remote repository.
# cd /local/git/project1 # git remote add gitorious git@gitorious.org:project1/project1.git # cd /local/git/project2 # git remote add github git@github.com:user/project2.git
See git-remote(1) for more info.
Before you do this, you will have to register an account at those sites, obviously.
Also, you will have to create empty Git repositories at those sites.
If you want this module to push commits to a remote Git repository like Github or Gitorious, you will need to upload a public SSH key to those sites.
The creation of SSH keys is beyond the scope of this manual page; see ssh-keygen(1) for more info.
Warning!
Although it's perfectly legal to generate passwordless SSH keys, I strongly advice against it (and so will the administrator of the remote Git repository). If your key should ever get compromised, it will give full access to the remote Git repository (which is your repo).
A better option would be to use a tool like keychain(1).
The best solution would be to not have this module push the changes to the remote Git repository, but to do it manually.
All options are available both as commandline options to svnnotify and as YAML keys for use by SVN::Notify::Config (see their respective manual pages for more info).
Specified on the commandline as
--handler Git
or in an SVN::Notify::Config configuration file as
handler: Git
Tells SVN::Notify to use this module as a handler.
This parameter is mandatory.
Specified on the commandline as
--to "/path/to/git/repository"
or in an SVN::Notify::Config configuration file as
to: "/path/to/git/repository"
Specifies the path to the local Git repository.
This parameter is mandatory and should be an absolute path.
Specified on the commandline as
--svn-binary "/path/to/svn/executable"
or in an SVN::Notify::Config configuration file as
svn_binary: "/path/to/svn/executable"
This specifies the path to the svn program. If this is not
specified, the PATH will be searched.
This option is only used if the --rewrite-author option is given.
Specified on the commandline as
--rewrite-author
or in an SVN::Notify::Config configuration file as
rewrite_author: 1
When this option is specified, the name of the author in the Subversion
log will be rewritten to what svnnotify would have used if it would
have sent a notification mail (which depends on the username of the
committer and the from and user_domain options; see the
documentation for svnnotify).
For this to work, there should be a pre-revprop-change hook in the
Subversion repository (see above).
Specified on the commandline as
--remote "name_of_remote_git_repo"
or in an SVN::Notify::Config configuration file as
remote: "name_of_remote_git_repo"
If this option is specified, this module will try to push the changes from the local Git repository to a remote Git repository.
See above for more info on how to prepare the local and remote Git repositories.
Rob la Lau <rob@nerdstock.org>
Comments are welcomed.
Currently only the SVN::Notify::Config variant has been tested.
It is currently undefined what will happen if multiple Subversion commits trigger this module at (approximately) the same time. (The subversion sources (libsvn_repos/hooks.c) suggest Subversion waits for hooks to finish, which would mean there could never be clashes. I have not been able to test this, though.)
When using SVN::Notify::Config, make sure to set the PATH environment
variable, because git needs to be able to find tools like basename,
sed, uname and mkdir.
Copyright (c) 2010 Rob la Lau
This program is free software; you can redistribute it and/or modify it under the terms of version 2 of the GNU General Public License, as published by the Free Software Foundation.
The GNU General Public License can be found at http://www.gnu.org/licenses/licenses.html
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.