0

This is a follow-up to this previous question. So there you can find what I did so far.

In short, I created a new git branch branching from a branch that is dcommit'ed to a remote svn repository. This new git branch is intended to only be used locally and never to be synchronized with the svn. While I can ensure this manullay as explained in this answer, the new git branch 'remembers' its svn origin:

$ git svn info
Path: .
URL: [path-to-host]/[svn-repo]/trunk
Repository Root: [path-to-host]/[svn-repo]
Repository UUID: [repository-uuid]
Revision: [revision]
Node Kind: directory
Schedule: normal
Last Changed Author: sg-lecram
Last Changed Rev: [revision]
Last Changed Date: [date]

So assume if I checkout the new git branch and commit some changes to the local git, I could run git svn dcommit sending the changes to the svn. While I do not plan to do this, all it needs is to forget for a split-second on which branch I am on to publish all the secret changes in the secret git branch.

I would like to be able to unlink the new git branch from the svn so that trying to dcommit from that branch results in an error. How can I do this?

Community
  • 1
  • 1
mschilli
  • 1,884
  • 1
  • 26
  • 56
  • Not a git solution but in mercurial you can mark a branch as being in a secret phase - then it does not get pushed - would you consider switching to hg? – Steve Barnes Aug 20 '14 at 09:26
  • @SteveBarnes Since I already have history in the `git` + I still would have to sync with the `svn` + I never used `hg` before, I would like to avoid that. But it's nice to know and I might give it a try for my next project. – mschilli Aug 20 '14 at 10:21
  • I think that you would be pleasantly surprised. – Steve Barnes Aug 20 '14 at 21:14

2 Answers2

1

You can't. git-svn finds the associated subversion repository by searching history for a commit message containing a git-svn-id: ... line with a reference to a subversion commit recorded in git-svn's history. Once it arrives at commits from the subversion-tracking branch, it will find one.

I'd suggest to alias git to a script that hooks into svn dcommit, and checks whether you are in the correct branch before passing on to the real git command. While this requires you to modify your system outside the repository, its also by far the simplest solution.

All technical options I can think of require you to prevent git-svn from reading too far into history:

  • Create a second svn repository, add it as a second svn remote, checkout from it, and create an empty commit in your branch containing the reference line from that checkout. Afterwards, delete the svn repository. Trying to dcommit in that branch will now try to use the other svn server and therefore fail.
  • Work with orphan branches. If you checkout your new branch using git checkout --orphan new_branch_name, it will have a disjoint history and therefore not have any commit messages with valid references to svn.

With both solutions, merging your work branch back into its parent branch is more involved than usually. For the first option, branch again from your branch and then rebase -i against master skipping the first commit, then pull to master. For the second one rebase with --onto master and upstream set to the root commit of the branch.

Phillip
  • 13,448
  • 29
  • 41
0

Instead of "unlinking" with svn, you can use locally a pre-push hook to prevent you from pushing that branch name

**edit: ** svn dcommit does not have native hook, so you can use the solution given here : How can I avoid an accidental dcommit from a local branch

Community
  • 1
  • 1
Asenar
  • 6,732
  • 3
  • 36
  • 49