2

I have a problem with a repo git that I want migrate to svn. In this repo some branch was create with space in name. When I start command git svn cloneI have an error

fatal: Not a valid object name refs/remotes/origin/My branch
cat-file commit refs/remotes/origin/My branch: command returned error: 128

I dump my repo with svndumpfilter exclude but problem is same. I tried to clone in use ignore-path option, but is same !!

git svn clone --trunk=/Projet/trunk --branches=/Projet/branches --tags=/Projet/tags --authors-file=authors.txt file:///home/repo_svn/nom ../temp --ignore-path=".*(?:refs/remotes/origin/My branch|refs/remotes/origin/My%20branch)"

Have you a solution ? best regards

alex8276
  • 25
  • 8
  • 2
    Possible duplicate of [Migrating SVN (to Git) branches with white space in the names](https://stackoverflow.com/questions/33477630/migrating-svn-to-git-branches-with-white-space-in-the-names) – Enrico Campidoglio Jun 07 '18 at 14:26
  • Also, this thread might be helpful: [git svn clone: branches/tags with whitespaces not supported?](https://community.atlassian.com/t5/Bitbucket-questions/git-svn-clone-branches-tags-with-whitespaces-not-supported/qaq-p/240814) – Enrico Campidoglio Jun 07 '18 at 14:28
  • Hello Enrico, Yesterday I tried to modifiy the file packed-ref but after, I have an other error (has was not ok) – alex8276 Jun 08 '18 at 07:05

2 Answers2

4

This is probably too late for you, but on the off-chance anyone else hits this page, we had this problem too. The cause of the crash is indeed due to spaces in the branch name—specifically, the cmt_metadata() sub in git-svn.perl is calling cat-file with the unescaped branch name. I'd imagine it wouldn't be too hard to tweak this method to be more robust.

However.

While that was the cause of the crash, it turns out that even hitting this bit of code was a sign that we had something else wrong. Specifically, with multiple branches entries in the git config, the right-hand-sides of some of the rules were conflicting. We had something like

branches=/branches/a*:/refs/remotes/origin/*
branches=/branches/b*:/refs/remotes/origin/*

which I think is the default config you get if you use --branches=/branches/a* --branches=/branches/b* in your init or clone command lines. Turns out the right hand side of those rules greatly prefer to be distinguishable as well as the left. So starting from scratch with a git svn init, then editing .git/config, adding:

branches=/branches/a*:/refs/remotes/origin/a/*
branches=/branches/b*:/refs/remotes/origin/b/*

and kicking off a git svn fetch seems to have fixed it. Branches still have spaces, but no longer hit the code that doesn't like them.

Bob Arthur
  • 125
  • 1
  • 8
  • Thanks! This solved the problem for me too. I would just add that the right side doesn't need to match the left as long as it's unique: branches=/branches/tom*:/refs/remotes/origin/a/* branches=/branches/dick*:/refs/remotes/origin/b/* branches=/branches/harry*:/refs/remotes/origin/c/* – Mike Laughton Jun 15 '21 at 16:48
  • I had the same issue, found the branches and tags lines were duplicated, rather than adding the a and b, I just deleted the duplicate lines. That fixed it for me. – Chris Aaaaa Nov 30 '22 at 19:35
0

On my Mac, I edited:

/Applications/Xcode.app/Contents/Developer/usr/libexec/git-core/git-svn

went to this sub and added the call to quotemeta, seems to have fixed the problem for me, ymmv.

sub cmt_metadata {
  return extract_metadata((grep(/^git-svn-id: /,
  command(qw/cat-file commit/, quotemeta(shift))))[-1]);
}

Then the git svn clone worked fine.

  • Apparently doesn't work in Windows, because when modifying the script as described I end up with this: ```fatal: Not a valid object name refs\/remotes\/origin\/dmupdate``` ```cat-file commit refs\/remotes\/origin\/dmupdate: command returned error: 128``` Might be caused by \ as path delimiter. – Florian Straub Jan 26 '23 at 12:41