Search code examples
git-svn

git-svn: How to prevent "dcommit", "rebase" when not on master


I am using git-svn.

My problem is, I never want to be able to do a git svn rebase or even worse a git svn dcommit while I am on a local branch. I only want to do this while I am on the master branch.

How I can make sure that git prevents these operations ?

I tried to give dummies via git config branch.<name>.remote but this does not help for git svn rebase and git svn dcommit.

Any other ideas ?


Solution

  • An other idea would go like this.

    function git () {
      if [[ "$1" = svn ]] && [[ "$2" =~ dcommit|rebase ]]; then
        # allow git-svn dcommit/rebase only on master
        if git branch --show-current | grep -q master; then
          echo "Master branch check passed" >&2
          command git "$@"
        else
          echo "Disallowed - not on master" >&2
          return 1
        fi
      else
        # subcommand filter passthrough
        command git "$@"
      fi
    }
    

    This shadows /usr/bin/git with a bash function named git — all it does is detecting the commands you want to disallow to yourself, and passing them through (or not) to the real executable (command git).