9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

svnリポジトリの変更をgitリポジトリが追随するhookスクリプト

Posted at

svnからgitに切り替えるのはなかなかに大変というか、踏ん切りが付かないもので
gitで出来る事はsvnでも出来ちゃったりする事もあるので「svnのままでもいいじゃん」ってのがあります。
だけども新しいものを使いたいし、ちゃんとgitを使いこなし、branchを使いこなして開発を行いたいものであります。
少しずつでもいいからsvnからgitに移行できるようにsvnリポジトリでの変更があったら、gitリポジトリにも変更が反映させるというhookスクリプトを設置しておいて、いつでもgitリポジトリが最新になっていて、「gitリポジトリがあるんならこっち使っちゃえば良いじゃん」ってなれば良いなと妄想して調べてみた物がこちら。

git svn clone --prefix svn/ -s <svn_url> <git_path>
cd <git_path>

for branch in $(svn ls <svn_url>);
do
git branch ${branch} remotes/svn/${branch}
done;

cd <git_path>
vi .git/hooks/svn-rebase-all
.git/hooks/svn-rebase-all
# !/bin/sh

git=/usr/local/bin/git
date >> .git/svn-rebase.log
${git} reset --quiet --hard
for ref in .git/refs/heads/*
do
  branch=${ref##*/}
  echo Updating ${branch}
  ${git} checkout --quiet --force ${branch}
  ${git} svn rebase
done 2>&1 | tee -a .git/svn-rebase.log
${git} checkout --quiet --force master
chmod +x .git/hooks/svn-rebase-all

cd <svn_path>/
vi hooks/post-commit
# !/bin/sh

cd <git_path>
. .git/hooks/svn-rebase-all
chmod +x <svn_path>/hooks/post-commit

参考 : [svn - Automatically synchronizing a Subversion repository and a Git repository - Stack Overflow] (http://stackoverflow.com/questions/5586993/automatically-synchronizing-a-subversion-repository-and-a-git-repository)

あらかじめsvnのリポジトリサーバーでgit svn cloneをしておいて、gitのhookスクリプトにsvnの変更を取り込むスクリプトを置いておいて、svnでコミットがあった時にそのスクリプトを実行させるというものです。
gitでcloneしたローカルの方でbranchesのbranch切っておいてください。(なんかややこしいな)
svnの変更をgitのリポジトリに取り込んだので、後はgithubにpushするなり、取り込んだリポジトリをcloneするなりしてくればよしです。

参考リンクの方にはpushした時にdcommitしてくれるスクリプトもあるみたいだけど、そこまではまだ大丈夫かなー

9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?