Can I set hooks for "pull"/"push"ing from/to a git-svn
managed repository?
The situation is that I have a project host on Google Code, and use git to manage the local working copy. I want to set some hooks so that when checking in/out data from/to the SVN repository with git svn fetch
and git svn dcommit
, I can do some modification to the commit. Since I do not host the SVN repository, I can't set hooks on the server side.
Is there any hook I could use? Or is there a way to "mark" an ordinary branch, so that git pull
and git push
on that branch will check in/out from/to a SVN repository instead, therefore the normal git hooks could be used?
Thanks in advance.
A hook script is a program triggered by some repository event, such as the creation of a new revision or the modification of an unversioned property. Each hook is handed enough information to tell what that event is, what target(s) it's operating on, and the username of the person who triggered the event.
git-svn is a specialized tool for Git users to interact with Git repositories. It works by providing a Git frontend to an SVN backend. With git-svn, you use Git commands on the local repository, so it's just like using normal Git. However, behind the scenes, the relevant SVN commands are sent to the server.
Git hooks are scripts that run automatically every time a particular event occurs in a Git repository. They let you customize Git's internal behavior and trigger customizable actions at key points in the development life cycle.
As illustrated by this thread, you can have hooks on the Subversion side which can actually reject your git svn dcommit
based on some criteria.
But if you need git hooks on the Git side, I would recommend setting up an intermediate bare Git repository (bare for easy push/pull).
On that bare repo, you can have any hook you need, as shown in "how do I deploy multiple branches to different directories via git push?" (not about svn but just here to detail a similar setup of an extra repo)
git svn dcommit
.git fetch
request, trigger a git svn fetch
and validate it, before allowing your own git fetch
to move forward.(2 years later)
David Souther proposes a solution in his blog (April 2012)
The solution I have is to have a repository with split heads. Most of the time, the intermediate repository will have an empty working directory. When a push happens, it will check out master, verify the build, and push to svn, before returning to the empty branch.
We’re going to set up an intermediate git repo with two branches.
- master will still point to the SVN repo,
stage
will let us keep the working directory clean and in sync with downstream changes.Check out his gist.
https://github.com/hkjels/.dotfiles/blob/master/zsh/git-svn.zsh
If you use zsh, I believe this is a good companion for git-svn. Just put your hooks in .git/hooks and prefix the command with svn-.
Eg ".git/hooks/post-svn-rebase"
The script also enables the use of aliases
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With