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?

3 Answers 3

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 ...
Sign up to request clarification or add additional context in comments.

4 Comments

> "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.
That doesn't matter. If you can do a svn checkout <URI> you can also do a git-svn clone <URI>.
You can check out how submodules have changed to be able to track branches here,
@Matt true, I have added a link to this answer (which I wrote). Thank you for reminding me to update this post as well.
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.

5 Comments

that sounds horrible :)
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).
This costs a lot in term of disk usage, the history will be duplicated from SVN repo to git repo, so git repo will increase a lot if the SVN repo is a huge 3rd party code source...
Not really. You aren't committing the SVN repo into git, you're just committing in a checkout of the SVN repo into git. That's one point-in-time copy, not the entire history. Of course, every time you re-commit an updated SVN checkout to git, you are copying some new history.
It actually depend how often you update the svn repo. If you update it too often it's gonna cost a lot in term of disk usage
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.