Shallow clone with JGIT
Asked Answered
S

2

28

How I can do

git clone --depth 1 ...

with JGIT library?

Sedimentation answered 13/7, 2012 at 17:17 Comment(0)
M
16

You can't, JGit doesn't yet support shallow clones on the client side (it does on the server side, though).

Mindy answered 23/8, 2012 at 18:27 Comment(8)
this bug indicates that this is available now. Is it the case? bugs.eclipse.org/bugs/show_bug.cgi?id=301627Payment
Anyone found a way to do this?Gildagildas
Hmm, Jgit still doesn't support shallow clone as of this post. If you're like me and wondered how the Jenkins plugin offers a shallow option, then you also wouldn't be surprised to hear that those guys implemented an abstraction that falls back to jgit when linus git isn't available. I don't know how to use this outside of jenkins but here's the part with the abstraction: github.com/jenkinsci/git-client-plugin/blob/master/src/main/….Nate
To clarify @Payment 's comment: the mentioned bug is about the server implementation inside JGit, the server now supports shallow fetch if requested (see comment #13). git clone --depth however is not implemented yet, see bug 475615: Support "git clone --depth" in CloneCommandOrganizer
There is a WIP implementation of this on GitHub.Theis
@Theis do you have an example?Contaminate
By now bugs.eclipse.org/bugs/show_bug.cgi?id=475615 has been resolved and JGit 6.3.0 does support shallow clones / fetches on the client side.Coom
Some 11 years after the question was originally posed, it looks like an implementation now exists, in the (as yet unreleased) 6.5. Here's the PR: git.eclipse.org/r/c/jgit/jgit/+/196477Directional
O
4

According to the Release notes for version 6.5.0, this has been released on March 15, 2023.

You can now use any of

  • .setDepth(Integer)
  • .setShallowSince(Instant)
  • .setShallowSince(OffsetDateTime)

for example like so:

Git.cloneRepository().setDepth(1)
Oslo answered 21/4, 2023 at 7:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.