Lei
Lei

Reputation: 3551

Git SVN fetch nothing occasionally

Below svn branches have been added into .git/config file.

[svn-remote "svnb02"]
        url = https://svn/repos/Project/branches/b02
        fetch = :refs/remotes/git-svn-b02
[svn-remote "svnb03"]
        url = https://svn/repos/Project/branches/b03
        fetch = :refs/remotes/git-svn-b03

But only "svnb03" can be fetched using below command:

git svn fetch -R svnb03 -r HEAD

For "svnb02", below command will return quietly without fetching anything.

git svn fetch -R svnb02 -r HEAD

Any commed will be welcome.

Upvotes: 3

Views: 7641

Answers (4)

Lantern Rouge
Lantern Rouge

Reputation: 43

git svn clone will also fail silently if your subversion repo does not have the standard layout with trunk, branches, and tags at the top level. If that is the case, restructure your repo and git svn clone should work.

Upvotes: 3

Kurt Harriger
Kurt Harriger

Reputation: 2527

This occurs if the requested revision (HEAD) is not on the trunk. Our build scripts automatically tag the source after successful build so in my case the last svn revision rarely ever points to the trunk so I get this a lot. The following script will get the last modified revision of the trunk and use that when performing the fetch:


#! /bin/sh
URL=$1
# git-svn fails to pull files if specified revision is not in path specified
# so find the last changed revision and use that
REV=$(svn info ${URL}trunk | grep "Last Changed Rev:" | awk '{print $NF}')
[ -n "$REV" ] || {
  echo "Revision not found. Check URL"
  exit 1
}
git svn init "$URL" -s --prefix svn/
git svn fetch -r $REV

Upvotes: 2

Jesse Eichar
Jesse Eichar

Reputation: 1081

Note I am a new user so can only have one hyperlink in my reply. Assume that BASE is "https://svn/repos/Project".

My answer is not directly the cause of this issue but it is closely related and is almost certainly a factor.

The problem is related to the fact that you are treating an SVN branch as the git trunk. I have found that new versions of git (1.6+) don't allow you to check out branches or tags as the git trunk. Git assumes a standard layout. In your case it probably assumes.

trunk - {BASE}/trunk/ branches - {BASE}/branches/ tags - {BASE}/tags/

Since b02 and b03 are children of branches it thinks they are branches and not trunk. In late 1.5.x versions I found that the behaviour is not very consistent but in 1.6.x versions (especially later 1.6.x versions) the behaviour is quite repoducable.

The work around that has worked for me very well is to explicitely declare tags and branches URLS:

git svn init -T {BASE}/branches/b03 -b {BASE}/anydir -t {BASE}/tags git svn fetch -r33666 # where 33666 is the most recent version.

There after I suggest using git svn rebase.

Upvotes: 1

Paul
Paul

Reputation: 16315

Maybe branch HEAD is not being set. Look at .git/remotes/svnb02/HEAD. If it's missing or not up-to-date, that might account for your problem.

Git has code to find HEAD in this situation, but apparently git svn doesn't; there's a patch in the works about this.

If that's okay, then I'd look for a weird entry to a svn. or remote.svn. variable in the config file or something weird in the .git/remotes directory.

This is all guesswork. A weird situation usually has a weird explanation. Good luck.

EDIT -- I'm assuming that svnb02 had new revisions when you had this problem. Your command is only going to fetch from svn if there are un-fetched revisions.

Upvotes: 2

Related Questions