Is it possible to have a Subversion repository as a Git submodule?

后端 未结 6 1972
南方客
南方客 2020-12-04 05:02

Is there a way to add a Subversion repository as a Git submodule in my Git repository?

Something like:

git-svn submodule add https://svn.foo.com/svn/         


        
6条回答
  •  庸人自扰
    2020-12-04 05:15

    I just went through this. I'm doing something similar to rq, but slightly different. I setup one of my servers to host these git clones of the svn repos I need. In my case I only want read-only versions, and need a bare repo on the server.

    On the server I run:

    GIT_DIR=.git git init
    cd .git/
    GIT_DIR=. git svn init svn://example.com/trunk
    GIT_DIR=. git svn fetch
    git gc
    

    This sets up my bare repo, then I have a cron script to update it:

    #!/usr/bin/python
    
    import os, glob
    
    GIT_HOME='/var/www/git'
    
    os.chdir(GIT_HOME)
    os.environ['GIT_DIR']='.'
    gits = glob.glob('*.git')
    for git in gits:
      if not os.path.isdir(git):
        continue
      os.chdir(os.path.join(GIT_HOME, git))
      if not os.path.isdir('svn/git-svn'):
        #Not a git-svn repo
        continue
    
      #Pull in svn updates
      os.system('git svn fetch && git gc --quiet')
      #fix-svn-refs.sh makes all the svn branches/tags pullable
      os.system('fix-svn-refs.sh')
      #Update the master branch
      os.system('git fetch . +svn/git-svn:master && git gc --quiet')`
    

    This also requires fix-svn-refs.sh from http://www.shatow.net/fix-svn-refs.sh This was mostly inspired by: http://gsocblog.jsharpe.net/archives/12

    I'm not sure why the git gc is needed here, but I wasn't able to do a git pull without it.

    So after all this you can then use git submodule following rq's instructions.

提交回复
热议问题