Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » Need JGit help(Need JGit help to perform specific operations)
Need JGit help [message #1853981] Tue, 26 July 2022 19:10 Go to next message
Joseph Gagnon is currently offline Joseph GagnonFriend
Messages: 4
Registered: July 2022
Junior Member
I am writing an application for the purposes of creating (and restoring from) archives of GitLab projects. Archived repos would be stored as zipped tar files and stored on an external removable drive. Many of the projects use LFS and we need to be able to successfully archive and restore these large files as well.

I am attempting to use JGit to perform various git-related operations on the repos to be archived and restored. I'm not having much luck finding information on how to make use of the JGit ecosystem to do some of these operations. The user guide is very bare bones. I have found another site (https://github.com/centic9/jgit-cookbook), that has provided useful information, but does not cover some of the other operations I need to perform.

I think the main problem I'm having at this time is that I'm having trouble understanding how to get access to a remote git repo. Maybe I'm missing it, but I can't find anything that seems to allow this in the Repository, RepositoryBuilder or Git classes. There doesn't seem to be any support for a remote URL/URI, except for Git.cloneRepository.

Here are a number of the operations that I need to perform:

For archival:

lfs fetch --all

For restoration:

git config credential.helper 'cache --timeout=36000'
git config lfs.activitytimeout 36000
git remote rename origin old-origin
git remote add origin
git push -u origin --all
git push -u origin --tags
git lfs push --all origin

To be honest, I'm not 100% sure if the process that includes these operations is "correct" to achieve the goal mentioned above. I am basing this on a process written by someone else. I don't know if it actually works.

I need to know how to be able to execute these operations, but don't know enough about how to do it with JGit. If anyone could provide ideas of what to do, or point me to examples where this is being done, it would be very much appreciated.

Somewhat off topic, if there is a better way to do this, please let me know. My application uses other libraries to handle invoking the GitLab REST API and deal with tar file operations, etc.

[Updated on: Tue, 26 July 2022 21:12]

Report message to a moderator

Re: Need JGit help [message #1854248 is a reply to message #1853981] Tue, 09 August 2022 06:52 Go to previous message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 1268
Registered: July 2009
Senior Member
Most of the git commands work on a local clone of the repository.
git has the following commands (corresponding JGit classes in brackets) acting on a remote repository:

git clone (CloneCommand)
git fetch (FetchCommand)
git push (PushCommand)
git ls-remote (LsRemoteCommand)

all other commands act on a local clone of the repository.

JGit provides basic LFS support and may lack some of its features.
I don't use LFS anymore hence I am not working on improving LFS support.
Find the LFS implementation in org.eclipse.jgit.lfs and org.eclipse.jgit.lfs.server and the corresponding test bundles.
AFAICS JGit does not yet support git lfs fetch --all and git lfs push --all.

The best source for basic examples how to use JGit are its unit tests. There are thousands.
You can also look at how EGit uses JGit, see https://git.eclipse.org/r/plugins/gitiles/egit/egit/
High level API classes are in package org.eclipse.jgit.api in the JGit core bundle org.eclipse.jgit.

JGit does not support git credentials helpers. All TransportCommands acting on a remote repository
accept a CredentialsProvider to support authentication.
Previous Topic:Git Clone Wizard Very Slow Vs. Git Command Line
Next Topic:option to delete untracked files on git reset
Goto Forum:
  


Current Time: Fri Apr 26 08:49:03 GMT 2024

Powered by FUDForum. Page generated in 0.02987 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top