How to access the Git repo that subgit has created.

Hi…

I’ve installed subgit on Ubuntu and configured it with our SVN repository. We access our SVN repository using svnserve. How do you suggest we access the git repository? I’m quite new to git.

Thanks
Ravindra

Hi Ravindra,

Git supports different remote protocols, such as git or ssh protocols; it can also be configured to be accessed over http but it would require a web server to serve the http requests. If the Git repository is on your local computer, then you can also use the file protocol or even access the repository using regular filesystem paths. Find more details on the protocols in Git documentation:

Git - The Protocols

Also note, that SubGit create a bare Git repository translating data from SVN, so you won’t see the files in the directory. To work with the files you would need to clone the repository with the git clone command.

Hi Ildar,

Thank you for the quick reply and also a big thanks for this wonderful product! It saved me countless hours of work!!

  1. Our SVN repo is on a server and I setup subgit with repo on same server. I read up a bit and came across git-shell. Seems similar to svnserve. I only have small issue…

We use svnserve via a user called svn:svn
I setup git:git user as suggested in your docs. git is part of svn group and vice-versa.
The git repositories are under

/git/project1.git
/git/project2.git

I made the /git directory the home dir of user git. However, ssh authentication fails because of bad ownership of git directory (owned by svn). Can I change it to owned by git? Will that affect subgit sync?

  1. I also setup sync with GitHub use the post-receive hook. However, I want different credentials to be used for project1 and project2. How do I store the credentials per repo? Can I run git config credential.helper store inside project1.git and then again under project2.git? This is really a git question but I thought I’ll check if you know how.

Regards and thanks,
Ravindra

Hi Ravindra,

if the Git repositories on the same server with SVN, then it makes no sense to use ssh to access SVN, use just the file protocol instead, like:

subgit configure --layout auto --trunk trunk file:///<path to svn repository> /git/project1.git

Also, the recommendation to use git user specifically relates mainly to GitLab environment, just because GitLab is running on behalf of that system user; but for not-GitLab setup you can use any user you want, so it’s not a problem to run SubGit on behalf of svn user.
The file ownership in Linux can be changed with chown command; file permission can be changed by chmod command.

Regarding the credentials question – not one hundred percents sure, but it looks for me that approach should work, indeed.

Hi ildar,

subgit is set up the way you’ve suggested. However, that server is remote to all of our users. To access that server via SVN we use svnserve (via svn+ssh). Since I go via svnserve our .ssh/authorized_keys file is set up to run “command…”. So I can’t access Git repo via same user. So I set up separate git user (unless you can suggest another way).

I symlinked /home/svn/svnroot/git/project1.git to /home/git/project1.git and was able to git clone on my laptop (using git clone git@<remote_server>:project1.git)

I was also able to fix the credentials issue for each repo.

The only issue is that the user-post-receive hook doesn’t fire. If I execute the file manually the changes are pushed to GitHub. The file permissions are correct and I also stored the git credentials so that git doesn’t prompt me for that. What could be wrong?

Regards,
Ravindra

If I run post-receive from command line it looks like it is waiting at the line HOOK_INPUT=$(cat)

Is there a way to run post-receive from command line to check that it works?

Regards,
Ravindra

Made more progrèss…

I ran hooks/post-receive from command line and entered user and hit Ctrl-D. This is what I get…

Everything up-to-date

SubGit ERROR REPORT (SubGit version 3.3.12 (‘Bobique’) build #4419):

You’ve received this message because SubGit (http://subgit.com/) is installed in your repository
and an error that needs to be dealt with has occurred in SubGit translation engine.

TEMPORARY ERROR:
Cannot stat file ‘/celoxis/home/celoxis/engr/svnroot/git/projects.git/hooks/svn/.svngit/svngitkit.config’ : No such file or directory

CURRENT STATE:
Both Git and Subversion repository are open for pushes or commits.
Your commit was not committed, but you may retry it.

TO RECOVER:
A) Address the problem if possible and then retry commit
OR
B) Run on the server
$ subgit uninstall SVN_REPOS_PATH

IMPORTANT: As soon as SubGit is uninstalled, both Git and Subversion repositories
will become open, but no synchronization will take place.

TO REPORT:
Report an issue at http://issues.tmatesoft.com/
You may find logs on the server at ‘SVN_REPOS_PATH/subgit/logs’

THANK YOU!
[2021-11-25 04:08:48.023][post-receive] SubGit version 3.3.12 (‘Bobique’)
[2021-11-25 04:08:48.023][post-receive] Command name: post-receive.
[2021-11-25 04:08:48.023][post-receive] Current user: svn.
[2021-11-25 04:08:48.023][post-receive] Cannot stat file ‘/celoxis/home/celoxis/engr/svnroot/git/projects.git/hooks/svn/.svngit/svngitkit.config’ : No such file or directory
[2021-11-25 04:08:48.023][post-receive] at hook_config_load (config.c:526)
[2021-11-25 04:08:48.023][post-receive] at hook_repository_area_detect (repository.c:72)
[2021-11-25 04:08:48.023][post-receive] at hook_git_resolve_paths (hook.c:507)
[2021-11-25 04:08:48.023][post-receive] at internal_post_receive (post-receive.c:24)
[2021-11-25 04:08:48.023][post-receive]

Regards,
Ravindra

Hi Ravindra,

it appears I don’t follow you in the setup discuss: you mentioned pushing the data to GitHub, so my understanding was the intend is to migrate the SVN repositories to GitHub so that users clone them from GitHub, not from local SubGit repository, but from you recent email I realized you are trying to clone the local SubGit repository and so are supposed to do the rest users. Could you please elaborate a little what is the ultimate desired setup?
Further, judging from the repository path /home/svn/svnroot/git/project1.git you mentioned it looks that you’ve established so-called local mirror instead of remote which we usually don’t recommend as the local mode is deprecated and only left in SubGit for backward compatibility. Better to use the remote mode, it allows placing the repositories anywhere you need them, yet the SVN repository URL should be set as URL with the protocol prefix – file:// for local paths. There is no need to use ssh for the mirror itself (that is, not need to set ssh URL I SubGit runs on the same machine) but the URL should the file:// prefix anyway, that is what I meant.
Regarding the – do you mean SubGit’s hook? If yes, have you set the svn.triggerSvnPostReceive on?

Hi Ildar,

Attached is a pic of my setup. My intention is to have 2-way mirror with GitHub. However, the documentation says the following. Hence we needed the SSH access to the subgit mirror. Are you saying this is deprecated? Seems that you are saying do this (https://preview.subgit.com/remote-book.html) but in there use the file:// for the path to the SVN repo. That way it can be moved anywhere later. Correct?

Is the hook option called triggerPostReceive OR triggerSvnPostReceive

1.5 Fetch changes from GitHub

In order to maintain reliable two-way mirror using setup described above, Git users have to push their changes to SubGit-managed Git repository rather than submitting changes to GitHub repository directly.

We recommend to disable write access to GitHub repository and submit any Git changes through SubGit mirror only.

IMG_20211125_162232__01.jpeg

And if so, is it possible to make some config changes from local to remote now instead of uninstalling subgit and redoing everything? I’ve even pushed the repo to GitHub. Just that the hook to push to GitHub after commit to svn isn’t working.

  • R

Hi Ravindra,

SSH access is not deprecated, it was about the local SubGit’s mode, this is what’s deprecated and actually I would not recommend continue using it, better to switch to the remote mode. Regretfully, we don’t have any features to convert local mirror into a remote one, the only way is to establish the remote mirror from scratch and deinstall the local mirror.

I’ve switched to the Remote configuration.

Q) How I can use the file:// url since I have to configure each repository separately. So I had to use svn+ssh:// URL. That works.

The following things were not clear. May be update the documentation?

  1. It is not clear that the subgit configure is run on the Git server (especially confusing when I first did the local setup where subgit was run on svn server)

  2. The auth kept failing since the SSH private key was in OpenSSH format. Hunting online led me to conversion from OpenSSH format to RSA format. Better if you can check the key format instead of getting the obscure error.

Sync with GitHub

  • I updated the hooks/user-post-receive file with “git push --all --follow-tags websites”
  • permissions are set to u+gx
  • the GitHub credentials are stored correctly
  • running post-receive and user-post-receive manually works fine
  • but it won’t run automatically.

What am I missing?

Regards,
Ravindra

I don’t understand your question to the very end, frankly said. You can use the file:// prefix in the same way like any other protocol, but the thing is that you need to use it to establish the remote mode mirror:

subgit configure --layout auto --trunk trunk file:///<path to svn repository> /git/project1.git

Since SubGit is on the same server where SVN resides, there is no need to use SSH for the mirror, better to use the file:// protocol, but the crucial here is to establish a remote mirror instead of local mode mirror. I’m not talking about how users will access the SubGit repositories, I’m talking about how SubGit will access the SVN repositories.
The subgit configure command is supposed to run on the same machine where SubGit is installed and that is supposed to host the mirrored repositories. I’m not sure if that is the machine you called the Git server, but if yes, then you’re right, all the SubGit commands are supposed to run on the Git server.
Thank you for the suggestion about the key format, we will discuss it internally.
As for the hooks – I would not recommend changing the post-receive as SubGit relies on it and may re-create it at some point. Better to implement all the logic you need in the user-post-receive. This hook should always be triggered when a new push comes to a mirrored repository but by default it’s not triggered by a new SVN revision. To change this behavior set the svn.triggerSvnPostReceive to true in SubGit configuration file:

[svn]
    …
    triggerSvnPostReceive = true

Run subgit install against the repository to apply the configuration change.
Have you set this setting already?

Forgot to add that I tried setting triggerSvnPostReceive = true

Also tried triggerPostReceive = true (since somewhere I read that)

Also restarted the daemon for the repository.

I set this after running subgit install. Does that matter? If yes, can I do something to fix it or do I need to do all the steps all over again?

Regards,
Ravindra

Yes, it matters, subgit install should be invoked to apply configuration changes.

Can I run install again on an already installed setup?

sure, that’s regular operation for a mirror, SubGit will stop the daemon, apply all changes (if it’s possible to apply them) and start the daemon again.

Thanks. I gave it a try before your reply and it worked. So I finally managed it all… Remote SVN with sync to GitHub.

I have only 2 questions…

  1. This I asked earlier. Since I have to configure one project at a time how can I use file:// protocol because that only points to the main svn directory. One can’t find paths to individual projects inside svn. It is working fine with svn+ssh://

  2. In GitHub I see messages like the following for a few old branches

PSA_9_5_PATCHES had recent pushes 39 minutes ago

These are old branches and don’t have any recent pushes. Why does GitHub report that? How can I get rid of those messages? I don’t want to pull anything into the master.

Thanks again for your support.

Regards,
Ravindra

Hi Ravindra,

you can use the paths inside the repository with the file:// protocol the same way you do with svn+ssh://. Suppose the SVN repositories reside in /svn directory and you can access particular project in one of repositories using the following URL:

svn+ssh://host.domain.com/svn/repoN/projectM

If you have SubGit installed on the same server, then you can use the following URL to access the same project over the file protocol:

file:///svn/repoN/projectM

Regarding pushes, I’m afraid I cannot say for sure why it shows this messages, I have no details about the setup itself nor about the SVN repository and its history; may assume that it means the recent push from the SubGit repository to GitHub.