JGit : connect to distant repository - remote-access

I searched through Google, forums and JGit user guide but couldn't find how to connect to a distant repository with the API.
Anyone has an example or just an idea on how to do that?
Thanks for your help.

Currently, JGit 2.0.0-SNAPSHOT does only offer
org.eclipse.jgit.storage.file.FileRepository
org.eclipse.jgit.storage.dfs.InMemoryRepository
concrete Repository classes, meaning that since org.eclipse.jgit.api.Git takes a Repository, it is not possible to work remotely. Since Git by itself is not designed to operate remotely in the way I think you mean, I doubt we will see such a feature any time soon.
MORE ON THAT:
Consequently, you will need to clone locally. You do that by issuing
Git.cloneRepository()
.setURI(myRemoteURIString)
.setDirectory(new File(myLocalPathString))
.call();
However, for reasons of consistency in Git you should clone a bare repository only, so a non-bare repository in a remote location, while not technically, is practically inaccessible.

I am not sure I understand the question since Git is made for accessing other repositories, this is what is meant by "Git is distributed".
If you want to connect to ONE distant repository, then yeah you should clone it.
I don't know if that is what you are looking for, but you can also use multiple remotes. Adding one more is done with Git using git remote add <remote_name> <remote_uri>. As for Jgit, I unfortunately can't remember the code to do it simply, but you can figure this out.
At least it's possible by modifying the configuration, calling getConfig() from a Repository object and then calling setString(...) on it - don't forget to save the configuration in the end. But before modifying the configuration, I think you should first get to know more about Git and JGit.
I recommend you to read more about it, and play a bit with your repository. Take a look at this article : http://caiustheory.com/adding-a-remote-to-existing-git-repo .
Another one that will help you down the road is How do I do the equivalent of “git remote update” with jgit?
Maybe someone else knows exactly which commands to run and can help.

Related

Moving a Gitolite (3) server that is using Git Annex

I'm currently in the process of moving a gitolite (3) installation between two
servers. Thankfully, this process is pretty well
documented on the main
project website. However, my repositories makes pretty active use of
git-annex which stores data in various
remotes as well as on the server itself.
Now, I'm not an expert on git-annex, but I know it works a bit differently from
"regular" git, so is there anything one should keep in mind when moving this
kind of installation or does it work just as outlined in the gitolite
documentation above?
After quite a bit of research, I couldn't find any details on how this should
done on a git-annex enabled repository so I decided to simply try it
out. Apparently, the steps as they are written work just fine, even for
git-annex content. That said, be cautious as you're moving stuff. Once the new
server is ready to take over, make sure the old one is disabled, I don't think
the git-annex likes to find 2 identical remotes.
As a minor anecdote: I accidently forgot to chown/chmod the repositories but
re-running step 6 and onwards without any issues what-so-ever.

gitlab clone fails with could not read from remote repository

While trying to clone a repository from gitlab, I ran into the following error:
git clone <USER>#<URL>:<path_to_project.git>
Cloning into 'xxx'...
<USER>#<URL>'s password:
fatal: 'root/acl-labl-website.git' does not appear to be a git repository
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I tried both the SSL and HTTP address, and both got this similar error. Not sure what it meant, and after many tries involving modifying config files (from gitlab, nginx, apache checking redirects, etc.), I found the very simple answer. Still not sure why my other method didn't work, but I found that first adding your public ssh key to gitlab (through the GUI), then using the same command as above, but using git instead of my username:
git clone git#<URL>:<repo_path>.git
worked. I.e. generate your id_rsa.pub as explained here: https://docs.gitlab.com/ce/ssh/README.html , copy this to your ssh keys (which in my case was one of the tabs in the gitlab GUI; I've done this before for git as well, where it's also to be found somewhere in your user settings). In my case I had to run
ssh-add
still before it worked, but with a colleague it worked without as well.
Then the cloning using git# instead of username# worked perfectly. Again; still not sure why it won't work using my username and password (same as the one I use to login to the gitlab GUI), so if someone could shed some light on that, I'd be interested in it. But since it took my quite some time before I found this solution/work-around, thought I'd post it here. Perhaps better suited to serverfault actually, but since I suspect many people end up here as well, perhaps the admins can live with this post here :)

Setting Commit and Checkout Privileges for a Git Repository

We are having a local repository which is accessible to a large number of people. We have to set up a Git repository there such that only certain users have checkout as well as commit privileges. How can we do that.
P.S. : This is a part of our homework assignment in which we have to develop a game and update it using a Git repository. So, if anyone feels like we should not be asking this question here, please do tell.
I'd recommend gitolite to manage user access to the repository.
Edit after comments:
gitolite is installed via git too.
I'm guessing that your teacher probably also meant to teach you – besides using git – to configure git protocols, ssh access (keys etc.).
You already got best advices: gitolite, gitosis, Pro git, adding to this man ssh, man ssh-keygen, man scp and git manual your homework should be easily solved.
Since it is homework I will try to give hints.
What files and directories do other users need to read to access (or write to commit/push into) a repository?
What methods can you use to control the permission on these files and directories?
Does your application have any configuration options that might help?

SVN server hosting company shutting down, and I need a backup of repository

I just logged onto http://www.ezsvn.com, that hosts my SVN repository. I have been paying monthly for hundreds of commits.
They're shutting down, and their support is nonexistent.
Can I get a backup of my repository from my machine? I’m using Windows.
If you have shell access:
http://wiki.archlinux.org/index.php/Subversion_backup_and_restore
If you don't have shell access (look at both the original answer and also the comments re: svnsync):
http://moelhave.dk/2006/07/remote-mirroring-a-subversion-svn-repository/
If you have access to run svnadmin on their server, it'll be no problem, and I see Dav has already linked to instructions for that.
Now, if you don't have access to run svnadmin, as far as I know it's not possible to use the SVN client itself (maybe TortoiseSVN for you) to copy the entire repository. (EDIT: never mind, I guess that was wrong. I'll leave the git info here just for the fun of it though.) But you can convert a whole Subversion repository to git, and here are instructions for doing that: http://pauldowman.com/2008/07/26/how-to-convert-from-subversion-to-git/ From there, you might be able to convert the git repository back into an SVN repository on another server. I know it's not really the answer you were looking for but if nothing else works, it will at least let you save your project's history in some form. (And hey, you could take it as an excuse to switch to distributed version control, which is all the rage these days)
If you really want/need the full history of your repository, you'll have to either get a dumpfile from the provider or get it yourself - some of the responses so far have addressed this already.
Another option: if you are not concerned with past revisions, but want your repo at it's latest state, just checkout the head revision, and export it to a separate location on your computer. That way, you have all your work to this point. You could then keep that as a backup, or possibly create an SVN account elsewhere, and import the exported copy into a fresh repo, then you would be back in business.

How to set up a git repository where different users can only see certain parts?

How do you set up a git repository where some users can see certain parts of the source code and other users can see all of it? I've seen lots of guides for only giving certain users commit access, but these assume everyone should have read access. I've also heard of gitosis, but I'm not sure it supports this and it hasn't had any commits in over a year so I think it's dead.
In short: you can't. Git is snapshot based (at conceptual level at least) version control system, not changeset based one. It treats project (repository) as a whole. The history is a history of a project, not a union of single-file histories (it is more than joining of per-file histories).
Using hooks like update-paranoid hook in contrib, or VREFs mechanism of gitolite, you can allow or forbid access to repository, you can allow or forbid access to individual branches. You can even forbid any commits that change things in specified subdirectory. But the project is always treated as a whole.
Well, there is one thing you can do: make a directory you want to restrict access to into submodule, and restrict access to this submodule repository.
The native git protocol doesn't support this; git assumes in many places that everybody has a complete copy of all of the history.
That said, one option may be to use git-subtree to split off part of the repository into its own subset repository, and periodically merge back.
Git doesn't support access control on the repository. You can however, implement access control on the repository yourself, by using hooks, more specifically the update hook.
Jörg has already pointed out that you can use hooks to do this. Exactly which hook(s) you need depends on your setup. If you want the permissions on a repo that gets pushed to, you'll need the update hook like he said. However, if it's on a repo that you're actually working in (committing and merging), you'll also need the pre-commit and post-merge hooks. The githooks manpage (Jörg linked to this too) notes that there's in fact a script in the contrib section demonstrating a way to do this. You can get this by grabbing a git tarball, or pull it out of git's gitweb repo: setgitperms.perl. Even if you're only using the update hook, that might be a useful model.
In general, Git is not intended for this. By now it seems to have out-of-the-box access control only up to the repository level.
But if you need just to hide some part of secret information in your Git repository (which is often the case) you can use git-crypt (https://github.com/AGWA/git-crypt) with encryption keys shared based on users GPG keys (https://gnupg.org/).
Alternatively you can use git submodules (https://git-scm.com/book/en/v2/Git-Tools-Submodules) if you can break your codebase to logical parts. Then all users receive access only to certain repositories which you then integrate into 'large' codebase through sub-modules where you add other code and allow it for only 'privileged' users.

Resources