Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » JGit checkout below project root(I need to clone starting from a subdirectory only)
JGit checkout below project root [message #1842411] Fri, 18 June 2021 01:26 Go to next message
Michael Croft is currently offline Michael CroftFriend
Messages: 2
Registered: June 2021
Junior Member
I have a repository that has a RELEASE directory that has code in the very constrained format used by the app it's being incorporated into. I can't fix the restriction, so I'm trying to come up with a JGit solution to use.

The app, which currently uses SVN, is running into some issues with github's SVN proxy, so it's a great time to just stop using SVN to check out git-based projects from GitHub.

svn (should) be able to take the URL (svn checkout https://github.com/Loathing-Associates-Scripting-Society/autoscend/branches/master/RELEASE/) and create a local copy starting at the RELEASE directory.

All I need to do is clone the project, but only

So my first problem is that I don't know how to do that in git. I think it's tied to the --filter command.

And my second is that I don't know how to do that in JGit. Can --filter options be applied to the porcelain "clone" command prior to .call()?

The sample-code-based code I'm using is:

                        String REMOTE_URL = params;
                       // should be: "https://github.com/Loathing-Associates-Scripting-Society/autoscend/branches/master/RELEASE/";

                        if ( !localPath.delete() )
                        {
                               // throw new IOException( "Could not delete temporary file " + localPath );
                        }

                        // then clone
                        System.out.println( "Cloning from " + REMOTE_URL + " to " + localPath );
                        try ( Git result = Git.cloneRepository()
                                              .setURI( REMOTE_URL )
                                              .setDirectory( localPath )
                                              //.setProgressMonitor( new SimpleProgressMonitor() )
                                              .call() )
                        {
                                // Note: the call() returns an opened repository already which needs to be closed to avoid file handle leaks!
                                System.out.println( "Having repository: " + result.getRepository().getDirectory() );
                        }


Thanks for any help or pointers to documentation!
Re: JGit checkout below project root [message #1842421 is a reply to message #1842411] Fri, 18 June 2021 08:30 Go to previous messageGo to next message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 1268
Registered: July 2009
Senior Member
Git is a distributed versioning system, this means you typically first clone the repository to your local disk
and then work most of the time on the local clone. You only need to contact the upstream repository
in order to exchange new commits created in your local repository or pushed by other developers to the
upstream repository.

As soon as you cloned the repository, and if you didn't clone it as a bare repository, you can check out whatever version
you are interested in and look at the files ending up in the so called working tree where the version you selected was
checked out to.

# clone the repository
git clone https://github.com/Loathing-Associates-Scripting-Society/autoscend/
# cd into the working tree
cd autoscend
# checkout e.g. the upstream master branch and create a new local branch master you can work with
git checkout origin/master -B master
# find the content of the RELEASE directory
find RELEASE
Re: JGit checkout below project root [message #1842431 is a reply to message #1842411] Fri, 18 June 2021 19:06 Go to previous messageGo to next message
Michael Croft is currently offline Michael CroftFriend
Messages: 2
Registered: June 2021
Junior Member
Thanks for replying.

Our use case is perhaps atypical. The vast majority of our users don't interact with a repository at all, developers create automation scripts with their existing tool chains and want to use a VCS, which is usually GIT on GitHub, and some users need to install the packages developers create.

End-Users interact with SVN via checkout/update commands we run for them in our app via SVNKit integration.

Due to some issues with GitHub's SVN proxy, we're trying to offer git clone/pull options via JGit.

So, basically, my predecessors in this project created a package manager backed by a VCS tool and I want to extend it to use GIT where We were previously using SVN.

To do this I need to either use something similar to SVN's capability to restrict a co to a subdirectory and children or I need to redesign my feature.

I'm looking to get guidance on how I can (or if I can) use jgit for my task.
Re: JGit checkout below project root [message #1842484 is a reply to message #1842431] Mon, 21 June 2021 12:38 Go to previous message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 1268
Registered: July 2009
Senior Member
I think your example is atypical. In native git there is an experimental feature sparse checkout [1]
maybe that's closer to what you want. Though this is not implemented in JGit.

[1] https://git-scm.com/docs/git-sparse-checkout
Previous Topic:PathSuffixFilter not worked with negate in jgit diff
Next Topic:JGit orphan branch checkout
Goto Forum:
  


Current Time: Sat Apr 27 02:38:04 GMT 2024

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

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

Back to the top