4

I'm using git as the revision control software for a project. My project needs to use a 3rd party code library which uses SVN for its revision control software. (In this case the 3rd party code is a PHP framework called Yii, not that it is very relevant to the question).

Is there a way to set up a external dependency in git that can help pull in code from a external SVN repository and keep it up to date?

If my project was using SVN, it would be trivial to set up because I would just do:

> svn propset svn:externals yii-1.1.6 https://yii.googlecode.com/svn/tags/1.1.6/framework

...then, whenever I did a svn checkout (or svn update), I would suck down the yii codebase into a local folder called "yii-1.1.6". Can I do something similar in git? Does anyone have an example in a public github repo that I can copy? I'm sure it must be a common need?

Tom
  • 14,041
  • 16
  • 64
  • 80

3 Answers3

6

You can do a git-svn clone of your svn repo, and then include that repo into your main Git repo, declaring it as a submodule.

Simply remember: git submodules are not compatible with svn submodules, in that they always refer a fixed version. See:


However, as I mention in "git submodule tracking latest", you can since git 1.8.2 (March 2013) track the latest of a branch of a repo through submodule.

$ git submodule add -b <branch> <repository> [<path>]
$ git submodule update --remote ...
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • > "You can do a git-svn clone of your svn repo," - the problem is that it is not my svn repo - it is a 3rd party repo. – Tom Mar 17 '11 at 20:58
  • 1
    That doesn't matter. If you can do a `svn checkout ` you can also do a `git-svn clone `. – joschi Mar 17 '11 at 21:04
  • You can check out how submodules have changed to be able to [track branches here](http://stackoverflow.com/questions/9189575/git-submodule-tracking-latest), – Matt Aug 25 '13 at 22:57
  • 1
    @Matt true, I have added a link to this answer (which I wrote). Thank you for reminding me to update this post as well. – VonC Aug 26 '13 at 05:32
3

You could also just SVN checkout the 3rd party library into your tree and then git add it (including all the .svn subdirectories) to your main project.

Kindof dirty but also kindof simple and straightforward.

When you need to update, just svn update and git commit.

Archie
  • 4,959
  • 1
  • 30
  • 36
  • that sounds horrible :) – shjeff May 17 '19 at 10:49
  • Agreed. It's just crazy enough to work :) One little nicety is that because git only stores identical files once, when you commit the checked out SVN repo, you only pay once for SVN's copying every file on checkout (which it does this so it has the originals to compare from). – Archie May 17 '19 at 14:28
1

I have exactly the same situation at work. I use SmartGit. I have .gitsvnextmodules file in the Git repository root (committed to Git).

[submodule "anyString"]
        path = path/to/svn/submodule
        url = https://url.of.svn/repository/blah
        revision = 1234
        branch = branches/branch #or it can be "trunk"
        fetch = trunk:refs/remotes/svn/trunk
        branches = branches/*:refs/remotes/svn/*
        tags = tags/*:refs/remote-tags/svn/*
        remote = svn
        type = dir

SmartGit displays it as a submodule pointing to "https://url.of.svn/repository/blah/branches/branch" (url+branch values concatenated) at revision 1234 (if it is not specified, HEAD revision is used). fetch+branches+tags are like in .git/config specification.

If you do not want to switch between branches of your 3rd party project quickly (I do because I also want to commit to a submodule), use something like this instead.

[submodule "alternativeSubmodule"]
        path = path/to/svn/submodule
        url = https://url.of.svn/repository/blah/branches/branch
        revision = 1234
        branch = /
        fetch = :refs/remotes/svn/git-svn
        remote = svn
        type = dir

More details in .gitsvnextmodules specification.

For this configuration SmartGit works with the submodule in the same manner like it works with usual Git submodules.

Dmitry Pavlenko
  • 8,530
  • 3
  • 30
  • 38