Question

I try to convert a subversion repo to git with "git svn ..."

(guide from http://john.albin.net/git/convert-subversion-to-git)

Unfortunately "git svn create-ignore" does not work:

config --get svn-remote.svn.fetch :refs/remotes/git-svn$: command returned error: 1

How can I get the svn:ignore properties to .gitignore files?

Was it helpful?

Solution

Answer to my own question.

I wrote a little script. You need the old SVN directory and the new git directory:

#!/usr/bin/python
import os, sys, subprocess

svn_dir=sys.argv[1].rstrip('/') # usage: python ... svn_dir git_dir
if not os.path.exists(os.path.join(svn_dir, '.svn')):
    print 'Not a svn-dir:', svn_dir
    sys.exit(1)

git_dir=sys.argv[2].rstrip('/')
if not os.path.exists(os.path.join(git_dir, '.git')):
    print 'Not a git-dir:', git_dir
    sys.exit(1)

for root, dirs, files in os.walk(svn_dir):
    dirs[:]=[d for d in sorted(dirs) if not d in ['.svn']]
    pipe=subprocess.Popen(['svn', 'propget', 'svn:ignore', root],
                          stdout=subprocess.PIPE)
    git_ignore_lines=[]
    for line in pipe.stdout.readlines():
        line=line.strip()
        if not line:
            continue
        git_ignore_lines.append(line)
    if not git_ignore_lines:
        continue
    git_ignore_dir=os.path.join(git_dir, root[len(svn_dir)+1:])
    if not os.path.exists(git_ignore_dir):
        os.makedirs(git_ignore_dir)
    git_ignore=os.path.join(git_ignore_dir, '.gitignore')
    if os.path.exists(git_ignore):
        old=open(git_ignore).read().split()
    else:
        old=[]
    old.extend(git_ignore_lines)
    fd=open(git_ignore, 'wt')
    seen=set()
    for line in old:
        if line in seen:
            continue
        fd.write('%s\n' % line)
        seen.add(line)
    fd.close()
    print 'wrote', git_ignore
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top