LoginSignup
1
0

More than 3 years have passed since last update.

GitレポジトリをSubversionレポジトリにミラーリングする(Git Server-Side Hook編)

Posted at

やりたいこと

gitレポジトリをsubversionレポジトリにミラーリングする。

git user -> git server -> svn server -> svn user

ポイントはgit serversvn serverのつなぎ。

さてどうしたものか。。。

とりあえず勉強だ!

Git Server-Side Hook(調査)

Gitのサーバーサイドフックは以下の3種類がある。

  • pre-receive
    • Pushリクエストをクライアントから受け付けた時に発動する(まだPushは完了していない)。pre-receiveはPushリクエスト一つにつき一度しか発動しない。non-zeroを返せば、失敗となり、Pushの処理は中止される。0を返せば成功し、Pushの処理は継続される。
  • update
    • 発動タイミングや成功・失敗はpre-receiveと同様。updateはブランチごとに発動する(Pushリクエストに含まれるコミットがそれぞれ異なるブランチのコミットとなっているような場合)。
  • post-receive
    • Pushの処理完了後に発動する。

GitLabでサーバーサイドフックを使う場合には、以下を参照。

For Omnibus installs the path is usually /var/opt/gitlab/git-data/repositories/<group>/<project>.git.

とあるが、わたしの環境ではrepositoriesの下はHash値になっている。

GitLabのAdmin Area>Projects以下にプロジェクト毎のページがあり、Gitaly relative path:という項目を参照すればプロジェクトのHash値がわかる。

Git Server-Side Hook(作成)

私はDockerを使ってGitLabサーバーを構築している。まずはサーバーにログインする。(gitlabという名前のGitLabサーバーインスタンスの想定)

% docker exec -it gitlab /bin/bash

フックを作成する。

# cd /var/opt/gitlab/git-data/repositories/@hashed/<group>/<project>.git/
# mkdir custom_hooks
# cd custom_hooks
# touch pre-receive update post-receive
# chmod +x pre-receive update post-receive

pre-receiveフックに以下の内容を記載してクライアントからサーバーへPushしてみる。Pushに失敗することを確認する。

#/bin/bash
exit 1
1
0
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
1
0