git-svn workflow for merging using svn.pushmergeinfo
Asked Answered
P

1

11

What is the correct workflow for merging svn tracked branches using git-svn. I've read a little about the git-svn svn.pushmergeinfo config key, and the caveats are:

From http://www.kernel.org/pub/software/scm/git/docs/git-svn.html:

config key: svn.pushmergeinfo

This option will cause git-svn to attempt to automatically populate the svn:mergeinfo property in the SVN repository when possible. Currently, this can only be done when dcommitting non-fast-forward merges where all parents but the first have already been pushed into SVN.

So my normal workflow is:

Assuming I have an SVN branch ^/branches/feature_branch

# Ensure git-svn is configured to populate svn:mergeinfo
git config --global svn.pushmergeinfo true   

# Update my local svn remotes state
git svn fetch

# Track a local branch against a remote SVN backed ^/branches/feature_branch 
git checkout -b local_feature_branch remotes/feature_branch

# Modify files and commit to local git repo
git commit -a -m "changes"
# Push changes to SVN branch ^/branches/feature_branch
git svn dcommit

Then to merge up ^/trunk into my local_feature_branch I assume I do something like?

# Sync to the latest SVN
git svn fetch
# Rebase "master" which is tracking the remote SVN ^/trunk
git checkout master
git svn rebase

# Checkout the local_feature_branch
git checkout local_feature_branch

# Merge "master" into "local_feature" which is tracking ^/trunk
git merge --squash master
git commit -m "merge master which is tracking SVN ^/trunk"

# Dry run the dcommit to SVN which should include svn:mergeinfo property changes
git svn dcommit --dry-run

# Commit merge to trunk
git svn dcommit 
Pentamerous answered 19/6, 2012 at 17:31 Comment(1)
Looks reasonable. What's the question about?Vet
P
20

Using merge --squash and svn.pushmergeinfo together doesn't make much sense. With merge --squash, the resulting commit won't be a merge commit, so a subsequent dcommit won't create any mergeinfo.

I know that (mostly older) threads here on stackoverflow suggest using --squash, but I think that's largely a relic of the past. I have been using git-svn to manage our company's svn repos for close to a year now, and so far it worked great with the following workflow:

I always make sure before a merge that I am up-to-date and, just to be safe, that I don't have any local unsynced commits:

# On local_feature_branch
# Update from SVN
git svn fetch && git svn rebase -l

# push pending commits
git svn dcommit

Then I do a 'real' merge, using the "remote" SVN branch as source. This saves switching branches and updating, and ensures that the incoming branch doesn't have any local unsynced commits:

# Create a real, non-forward merge commit
git merge --no-ff svn/trunk

# ... and push it to SVN, including mergeinfo
git svn dcommit

Also, this way the merge gets properly recorded in the local history, so subsequent merges won't have to deal with previously resolved conflicts. With --squash you'd reencounter those with every merge.

Note however that there is an open issue with mergeinfo when merging back from local_feature_branch to trunk (i.e. a reintegrate in svn-speak): Git-SVN with svn.pushmergeinfo: how to avoid self-referencing mergeinfo lines. This has happened rarely in our repo, but so far it didn't cause any trouble for me.

Pharmacist answered 20/6, 2012 at 10:36 Comment(6)
Do you have any details on avoiding the self-referential mergeinfo when merging the feature branch down to trunk?Pentamerous
No, so far I just ignored the issue without any problem. Not sure if some svn clients might have an issue with it, but so far we didn't experience any problems with git-svn, command-line svn or Eclipse Subversive (and I think Tortoise SVN, too)Pharmacist
EDIT Re-reading the detailed description at link, this probably never hit us because we've done all the (rare) reintegration merges that happened in that time with git.Pharmacist
I don't have an svn/trunk has git-svn changed how it names remote branches? Would it be remotes/trunk now?Voluptuous
@Sam short answer: Yes, it's remotes/trunk by default. Long-ish answer: git-svn will by default put all your "remote" svn branches directly under remotes/. In order to get a more familiar git-remote-like layout, I always use --prefix=svn/ with git svn clone/git svn init, which gives me remotes/svn/trunk etc. That's where my svn/trunk is coming from...Pharmacist
Now I wish I'd done that when I cloned. Presumably I can do the reverse of this: #4986879 to add the prefix. Although I'm not sure if that's a good idea according to this: blog.tfnico.com/2013/08/always-use-git-svn-with-prefix.htmlVoluptuous

© 2022 - 2024 — McMap. All rights reserved.