VisualSVN Subversion Server and Git

I’d like to start this blog with a few real-world examples on how to set up SubGit assuming infrastructure that is already in place. This post will take place in a strange world of Windows.

Initial configuration: VisualSVN Server on 64-bit Windows computer, provides read and write access to two Subversion repositories over HTTPS.

Primary Objective: Make Subversion repositories accessible for reading and modification with Git over HTTPS.
Secondary Objective: Reuse existing authentication settings, that are already configured for Subversion repositories.

In other words I’m about to set up instant bidirectional Svn to Git replication.

Configuration Details

This is a VisualSVN configuration I’ve created for this guide:

Initial VisualSVN Configuration

As you may see project repository is a single-project one with a standard trunk/branches/tags layout, and main repository contains two subproject, each with a standard layout.

VisualSVN is installed in C:\Program Files (x86)\VisualSVN Server directory.
Repositories are located in C:\Repositories directory.
VisualSVN uses standard Subversion authentication settings.

Add Git to Svn

First, install msysGit, you may download installer from their download page. Make sure you select this option when installing msysGit (it is important for enabling HTTP access later!):

Important Git Installation Option

Second, change an account VisualSVN service uses and modify C:\Repository directory (one where repositories are kept) permissions as described in a Visual SVN knowledge base entry. It is important to make VisualSVN service run on behalf of the account that has access to the Git you’ve just installed. Following the way of lesser resistance, I’ve used my personal account for that, but you may create a dedicated one.

After completing this step, I had VisualSVN service running on behalf of “HOST\alex” account and C:\Repository was writable for “HOST\alex”. Yes, my name is Alex.

Finally, download SubGit zip archive and unpack it into C:\SubGit directory. The run “subgit install” on Subversion repositories to enable replication:

> C:\SubGit\bin\subgit install C:\Repositories\main
> C:\SubGit\bin\subgit install C:\Repositories\project

Install SubGit

Install SubGit


Note, that you must run “subgit install” on behalf of the same user that you’ve configured VisualSVN service with.

Configure HTTP Access for Git

Important: VisualSVN comes with more or less truncated version of Apache, but fortunately it misses only one module of those needed for Git (mod_cgi). Download it (mod_cgi.so from Apache 2.2.21 for win32) and put into C:\Program Files (x86)\VisualSVN Server\bin directory.

Alternatively, you may get this missing module by installing Apache and taking mod_cgi.so file from the modules folder.

Then, edit C:\Program Files (x86)\VisualSVN Server\conf\httpd-custom.conf file:

LoadModule cgi_module bin/mod_cgi.so
LoadModule authz_user_module bin/mod_authz_user.so

SetEnvIf Request_URI "^/git/.*$" GIT_PROJECT_ROOT=C:/Repositories
SetEnvIf Request_URI "^/git/.*$" GIT_HTTP_EXPORT_ALL

ScriptAlias /git/ "C:/Program Files (x86)/Git/libexec/git-core/git-http-backend.exe/"

<Location /git>
  Options +ExecCGI

  Require valid-user
  AuthName "VisualSVN Server"
  AuthType Basic
  AuthBasicProvider file
  AuthUserFile "C:/Repositories/htpasswd"
</Location>

Note, that this configuration example uses “Basic” authentication option, granting read and write access to repositories for all Git users that are listed in htpasswd file. Of course you may configure something more complicated here.

Now restart VisualSVN Server service. That’s all!

Git for Svn

Try the following commands now:

# set this environment variable in case you're using SSL and 
# self-signed SSL certificate in VisualSVN (this is default).
> SET GIT_SSL_NO_VERIFY=true

> git clone https://alex@localhost/git/project project
> git clone https://alex@localhost/git/main/git/library lib

Thanks to SubGit, changes pushed from the cloned Git repository will be immediately propagated to the corresponding Svn repository and vice versa – new Svn revisions will be received by a pull performed from a cloned Git repository.

You may find more on SubGit at http://subgit.com/

20 thoughts on “VisualSVN Subversion Server and Git

  1. Thanks for the information.
    It seems there is a change in behavior.
    I need to use
    subgit install I:/Repositories/jose
    instead of
    subgit install I:\Repositories\jose

    Results from subgit install
    /e/subgit/bin subgit install I:\Repositories\jose
    SubGit version 1.0.0-EAP (‘Miai’) build #1096
    This is an EAP build, which you may not like to use in production environment.

    Detecting paths eligible for translation…
    Subversion to Git mapping has been configured in ‘I:\Repositoriesjose’:
    : I:\Repositoriesjose\.git

    Translating Subversion revisions to Git commits…

    Subversion revisions translated: 0.
    Total time: 3 seconds.

    INSTALLATION SUCCESSFUL

    Subversion repository path: ‘I:\Repositoriesjose’.
    You may now run
    git clone “I:/Repositoriesjose” “Repositoriesjose-git”
    to obtain Git clone of Subversion repository.

    /e/subgit/bin subgit install I:/Repositories/jose
    SubGit version 1.0.0-EAP (‘Miai’) build #1096
    This is an EAP build, which you may not like to use in production environment.

    Detecting paths eligible for translation…
    Subversion to Git mapping has been configured in ‘I:\Repositories\jose’:
    : I:\Repositories\jose\.git
    Translating Subversion revisions to Git commits…

  2. Hi,

    When trying a git push I get the following error any ideas:

    Counting objects: 4, done.
    Delta compression using up to 24 threads.
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 296 bytes, done.
    Total 3 (delta 0), reused 0 (delta 0)
    remote: bash.exe: warning: could not find /tmp, please create!
    remote: java.lang.NoClassDefFoundError: org/tmatesoft/translator/SubGitHook
    remote: Caused by: java.lang.ClassNotFoundException: org.tmatesoft.translator.Suremote:
    remote: at java.net.URLClassLoader$1.run(Unknown Source)
    remote: at java.security.AccessController.doPrivileged(Native Method)
    remote: at java.net.URLClassLoader.findClass(Unknown Source)
    remote: at java.lang.ClassLoader.loadClass(Unknown Source)
    remote: at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    remote: at java.lang.ClassLoader.loadClass(Unknown Source)
    remote: Could not find the main class: org.tmatesoft.translator.SubGitHook. Proremote: l exit.
    remote: Exception in thread “main” [chlewis@swsrvapps-01 ~/chris_test]$

    • Thank you for reporting this issue. I’ve created an issue for it (http://issues.tmatesoft.com/issue/SGT-433).

      It looks like Git pre-receive hook is started, but it fails to locate SubGitHook on the classpath. It would be great if you could take a look at repository/.git/hooks/pre-receive script to see if classpath is correct there. Thanks!

      • Hi,

        I have checked the file and the following is given (note no cygwin installed) how would i check, I can’t see where the SCRIPT_DIR variable is set :

        JAVA_HOME=”/C/Program Files (x86)/Java/jre6″
        JAVA_EXE=”$JAVA_HOME/bin/java.exe”
        MAIN_CLASS=org.tmatesoft.translator.SubGitHook
        TS_CLASSPATH=”$SCRIPT_DIR/../../subgit/lib/subgit-1.0.0-EAP_902.jar”:”$SCRIPT_DIR/../../subgit/lib/svngitkit-2.0.0-SNAPSHOT_r2748_v20111207_2017.jar”:”$SCRIPT_DIR/../../subgit/lib/svnkit-1.7.0-SNAPSHOT_r8358_v20111220_1803.jar”:”$SCRIPT_DIR/../../subgit/lib/commons-codec-1.4.jar”:”$SCRIPT_DIR/../../subgit/lib/sequence-library-1.0.0.jar”:”$SCRIPT_DIR/../../subgit/lib/sqljet-1.1.0-SNAPSHOT_r1158_v20110809_2108.jar”:”$SCRIPT_DIR/../../subgit/lib/antlr-runtime-3.1.3.jar”:”$SCRIPT_DIR/../../subgit/lib/jna-3.2.7.jar”:”$SCRIPT_DIR/../../subgit/lib/annotations-7.0.3.jar”:”$SCRIPT_DIR/../../subgit/lib/org.eclipse.jgit-0.11.3-sgk-SNAPSHOT_t20111003_2148.jar”:”$SCRIPT_DIR/../../subgit/lib/jsch-0.1.44-1.jar”:”$SCRIPT_DIR/../../subgit/lib/jansi-1.6.jar”

  3. when I use svn to commit

    Z:\test\trunk\1.txt
    Z:\test\trunk\1.txt
    Commit failed (details follow):
    Commit blocked by pre-commit hook (exit code 1) with output:
    access deined

    and when I use git push

    git push
    Password for ‘http://dd@192.168.12.3′:
    Counting objects: 4, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 287 bytes, done.
    Total 3 (delta 0), reused 0 (delta 0)
    To http://dd@192.168.12.3/git/test
    ! [remote rejected] master -> master (pre-receive hook declined)
    error: failed to push some refs to ‘http://dd@192.168.12.3/git/test’

    • Hello,

      Thank you for your feedback!

      The reason might be that you have installed SubGit on behalf of Administrator user (or on behalf of some other user), and repository files owner thus has been changed.

      At the same time VisualSVN’s Apache may be ran as a service with ‘Network Service’ privileges and may have no access to repository files or permissions to run newly created hooks.

      I would recommend you to change VisualSVN Apache service settings so that it is ran as Administrator, then restart the service.

        • First, clone Git repository

          > git clone http://dd@192.168.12.3/git/test test

          Then, in your Git repository clone, just run:

          > cd test
          > git checkout branchName

          This will work assuming your Subversion repository has the following structure:

          /trunk
          /branches
          /tags

          and your branch is located at /branches/branchName and has been translated during initial translation phase (when you were installing SubGit).

  4. git push
    Password for ‘http://dd@192.168.12.3′:
    Counting objects: 4, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 254 bytes, done.
    Total 3 (delta 1), reused 0 (delta 0)
    remote: bash.exe: warning: could not find /tmp, please create!
    remote: bash.exe: warning: could not find /tmp, please create!
    To http://dd@192.168.12.3/git/test
    7500d27..ec009f2 master -> master

    ======================
    remote: bash.exe: warning: could not find /tmp, please create!
    I can ignore the message?
    or I must add tmp path config in [hooks] and [daemon] ?

  5. subgit register –key c:\subgit.key svn_repo
    SubGit version 1.0.0-RC1 (‘Miai’) build #1519

    Registration information:

    Registered for: dd
    Purchase ID: dd
    Committers Limit: 3

    You may use this key to register 2 more repositories (out of 3).

    ==============
    then
    git clone svn_repo

    and I change git commit username & email ,modify code,git push over 3 times
    git config user.name user1
    git config user.email user1@xx.com
    ..modify
    git commit -m xxxx
    git push
    ==============
    git config user.name user2
    git config user.email user2@xx.com
    ..modify
    git commit -m xxxx
    git push
    …………………………..
    etc…….

    and No warning or error , says Committers Limit: 3?

  6. in my clean vmware xp 32 bit
    git push , to subgit installed repo ,very fast

    but in my win7 64 bit,
    git push ,
    Password for ‘https://dd@localhost’:
    Counting objects: 4, done.
    Delta compression using up to 4 threads.
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 251 bytes, done.
    Total 3 (delta 1), reused 0 (delta 0)

    show immediately
    ===================
    and wait about 70 seconds show
    remote: bash.exe: warning: could not find /tmp, please create!
    wait another 40 seconds to the second
    remote: bash.exe: warning: could not find /tmp, please create!
    To https://dd@localhost/git/dd
    fd612f8..ff87fed master -> master

    ==========
    and I create pure git repo
    then ,git push , no delay, pushed immediately

  7. When I install subgit then keep get following error. Can you please help?

    C:\>subgit install C:/JAVA/Repositories/test
    SubGit version 2.0.0 (‘Patrick’) build #2593

    INSTALLATION FAILED

    error: ‘C:\JAVA\Repositories\test’ is not a Subversion repository.
    error: Type ‘subgit help’ or ‘subgit help install’ for more information.

    Thanks,

    Robin

  8. Hello, I’m trying to transform my VisualSVN Server 2.1.5 into a Git server too.
    I followed everything that was described but still I don’t know what’s wrong because I keep getting this error:

    Request not supported: ‘D:/Repositories/Projetos/git/SN.git’
    [client XXX.XXX.10.68]

    And the diretory D:/Repositories/Projetos/git/SN.git exists.
    Do you guys know what could be wrong?

  9. It’s hard to find your posts in google. I found it on 22 spot, you
    should build quality backlinks , it will help you to increase traffic.

    I know how to help you, just type in google – k2 seo tips

  10. It’s hard to find your page in google. I found it on 17 spot, you should build quality backlinks , it will help you to rank to google top 10.
    I know how to help you, just type in google – k2 seo tips

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>