2

I work on a remote SVN repository using git-svn and I use git-flow workflow for my local development.

Unfortunately accidentally a couple of times I did the svn dcommit while being on a feature branch, while I want to only dcommit master.

What I'd like to do is to create a pre-svn-dcommit hook that would check whether I'm on the master branch or not. Unfortunately git doesn't seem to ship with such hook.

I did find two potential approaches/solution:

  1. https://github.com/padwan-ragavan/preSVNDcommitHook - I'm not too comfortable with replacing the git-svn binary though.
  2. http://davidsouther.com/2012/04/git-svn-dcommit-hooks/ - this on the other hand looks a bit too complicated for my liking (and needs).

Any advices how this can be achieved?

2

2 Answers 2

1

You could create a Git alias that throws an error when you're trying to commit on a non-master branch:

svndcm = "!f(){ if [[ $(git branch --no-color | sed -n "s/\* \(.*\)/\1/p") == "master" ]]; then git svn dcommit; else echo "Error"; fi }; f"

Include the above line in the [alias] section of your ~/.gitconfig file and then use git svndcm to dcommit your changes. Modify the alias name and error message to your liking :)

Sign up to request clarification or add additional context in comments.

Comments

1

As you note, there's no easy solution using Git natively. I achieve similar things by using the shell to catch calls to git and add additional features before calling git itself.

See How can I avoid an accidental dcommit from a local branch for a script that should do exactly what you're after.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.