1

I've a very strange problem with svn2git converter.

I have 2 svn repos (both svn 1.7 and developed in windows). I've created a python3 script to automatically sync the repos and push it to our gitlab server every day(the converter runs on a virtual ubuntu instance). Everything works just fine, but today i see that my repos are messed up. The first repo contains content from the second repo and the second repo contains content from the first repo. How could that be???

Does anybody has that kind of problem with svn2git? Does anybody know a good tool to automatically check repos per commit (svn vs git) to be sure that every commit is just fine?

Edit: Here is the script i use (it's a little bit hacky :-) )

# convert.py

import os,sys,subprocess

__filedir = os.path.dirname(os.path.realpath(__file__))
__migratescript = os.path.join(__filedir,"svn2git_repo/bin/svn2git")
__authors = os.path.join(__filedir,"authors.txt")
__repodir = os.path.join(__filedir,"repos")

class CurDirScope:
    def __init__(self,newdir):
        self.newdir = newdir
        self.olddir = os.getcwd()

    def __enter__(self):
        self.__chdir((self.newdir))

    def __exit__(self,type,value,traceback):
        self.__chdir(self.olddir)

    def __chdir(self,dir):
        if(os.path.exists(dir)):
            print("change current directory to {0}".format(dir))
            os.chdir(dir)

def gitSVNClone(directory,repo):

    dir = os.path.join(__repodir,directory)
    print("try clone {0} to {1}".format(repo,dir))
    gitpath = os.path.join(dir,".git")
    if(os.path.exists(gitpath)):
        raise Exception("repo directory does already exists {}".format(gitpath))
    print("create directory {0}".format(dir))
    os.makedirs(dir)

    with CurDirScope(dir) as scope:
        cmd = ["svn2git",repo,"--authors=" + __authors]
        print("start git svn clone")
        rc=subprocess.call(cmd)
        print("end of clone")
        if(rc != 0):
            raise Exception("git svn clone failed - rc: {0}".format(rc))

def syncRepo(directory):
    dirs = []
    if(directory == "all"):
        dirs = os.listdir(__repodir)
    else:
        dirs =[directory]

    if(len(dirs) <= 0):
        print("nothing to sync")
        return

    errors = []

    for dir in dirs:
        try:
            absdir = os.path.join(__repodir,dir)
            if(os.path.exists(absdir) == False):
                raise Exception("directory does not exists '{0}'".format(absdir))
            print(absdir)

            with CurDirScope(absdir) as scope:
                cmd = ["svn2git","--rebase","--authors=" + __authors]
                print("start git repo sync {0}".format(absdir))
                print(str(cmd))
                rc=subprocess.call(cmd,shell=False)
                print("end of sync")
                if(rc != 0):
                    raise Exception("rebase repo failed - rc: {0}".format(rc))

        except BaseException as ex:
            errors.append(str(ex))

    if(len(errors) > 0):
        print("# Error: ")
        for msg in errors:
            print(msg)
        raise Exception("{0} error(s) happend".format(str(len(errors))))

def pushRepo(directory,TagsOnly=False):
    dirs = []
    if(directory == "all"):
        dirs = os.listdir(__repodir)
    else:
        dirs =[directory]

    if(len(dirs) <= 0):
        print("nothing to push")
        return

    pushcommand = "--all"
    if(TagsOnly):
        pushcommand = "--tags"

    errors = []

    for dir in dirs:
        try:
            absdir = os.path.join(__repodir,dir)
            if(os.path.exists(absdir) == False):
                raise Exception("directory does not exists '{0}'".format(absdir))
            print(absdir)

            with CurDirScope(absdir) as scope:
                cmd = ["git","push","origin",pushcommand]
                print("start git repo push to origin '{0}'".format(absdir))
                print(str(cmd))
                rc=subprocess.call(cmd,shell=False)
                print("end of push")
                if(rc != 0):
                    raise Exception("push repo {0} failed - rc: {1}".format(dir,rc))
        except BaseException as ex:
            errors.append(str(ex))

    if(len(errors) > 0):
        print("# Error: ")
        for msg in errors:
            print(msg)
        raise Exception("{0} error(s) happend".format(str(len(errors))))



if __name__ == "__main__":
    try:
        args = sys.argv[1:]
        print(str(args))
        al = len(args)

        if(al <= 0):
            raise Exception("not enough arguments")

        cmd = args[0]

        args = args[1:]
        al = len(args)

        if(os.path.exists(__repodir) == False):
            os.makedirs(__repodir)

        if(cmd == "clone"):
            if(al < 2):
                raise Exception("not enough arguments for clone")

            dir = args[0]
            repo = args[1]
            gitSVNClone(dir,repo)

        elif(cmd == "sync"):
            if(al < 1):
                raise Exception("not enough arguments for sync")

            dir = args[0]
            syncRepo(dir)

        elif(cmd == "push" or cmd == "pushtags"):
            if(al < 1):
                raise Exception("not enough arguments for sync")

            tagsonly = False
            if(cmd == "pushtags"):
                tagsonly = True

            dir = args[0]
            pushRepo(dir,tagsonly)

        else:
            raise Exception("unknown command '{0}'".format(cmd))


    except BaseException as ex:
        if(ex == None):
            ex = "internal error"
        print("Error: {0}".format(str(ex)))
        sys.exit(1)

clone example:

python3 convert.py clone MyLocalDir http://mysvnrepopath

It clones my svn-repo to my local-repo directory (where all converted repos are stored) with the local directory name MyLocalDir

sync example:

python3 convert.py sync all

the parameter all sync every repo in my repo-directory. I could also use the directory name instead of MyLocalDir, but i used 99% the all parameter

push example:

python3 convert.py push all

pushtags example:

python3 convert.py pushtags all

Greetings Tonka

Michael Aigner
  • 4,820
  • 4
  • 21
  • 33
  • As it stands there isn't enough information in this question for us to answer, but I suspect that you've got a bug in your Python script. – ChrisGPT was on strike Apr 15 '15 at 19:19
  • Hey chris. Which information do you mean? I've checked my script multiple times (it's very small) but i can't find any bug. What i don't understand is how the converter got the wrong svn url because in the the .git config file there is the correct svn url. – Michael Aigner Apr 15 '15 at 19:23
  • What content got switched? How does that map to the existing Subversion repositories? Show us the Python script. – ChrisGPT was on strike Apr 15 '15 at 21:13
  • The content of my two svn repos is mixed into one git repo so it is garbage right now. I've never see that before because i think that in git only that would not be possible without any force mechanism. I will send you the content of my script in about 8 hours because at the moment because i'm at home now. – Michael Aigner Apr 15 '15 at 21:54

0 Answers0