Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hooks for git-svn

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.

like image 906
iamamac Avatar asked Jan 06 '10 16:01

iamamac


People also ask

What are SVN hooks?

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.

Can you use Git and SVN together?

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.

What are the hooks in Git?

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.


2 Answers

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)

  • if the intermediate repo validate your push, it could trigger the git svn dcommit.
  • it can also, on a 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,
  • and the new branch stage will let us keep the working directory clean and in sync with downstream changes.

Check out his gist.

like image 59
VonC Avatar answered Nov 11 '22 05:11

VonC


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

like image 44
hkjels Avatar answered Nov 11 '22 06:11

hkjels