1

I'm using Maven SCM to checkout a Git repository. I only need to clone one branch so I would like to add '--single-branch' to the clone command.

The documentation doesn't mention anything about using custom options so I assume it isn't straightforward but maybe there is a workaround.

Is this possible?

Hatchet
  • 21
  • 2
  • What I need is the behavior of `--single-branch` on Maven SCM Git. [It's absolutely possible to only clone one branch](https://stackoverflow.com/a/9920956/927493). – Hatchet Feb 02 '19 at 22:50

1 Answers1

1

My old answer from 2012 mentioning the single-branch option of git clone is not a duplicate of this question, which seeks to replicate that feature with the Maven SCM plugin.

Commit d327618 seems to indicate this is already the case:

clone only required branch

Git.cloneRepository().setURI( repository.getFetchUrl() ).setCredentialsProvider(
                              credentials ).setCloneAllBranches(true).setDirectory(
                              credentials ).setBranch( branch ).setDirectory(
                                           ^^^^^^^^^^^^^^^^^^^^
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • It still downloads all refs from the remote repository. I tried different SCM Git providers like JGit and by default there is no configuration that behaves like --single-branch. – Hatchet Feb 02 '19 at 22:49
  • @Hatchet Agreed. Maven Git SCM uses JGit anyway. – VonC Feb 02 '19 at 22:57
  • @Hatchet And the Maven GIt SCM codebase does not include "setBranchesToClone", which is what you would need to clone only one branch: https://www.eclipse.org/forums/index.php/t/1065371/, and even that would not not well: https://www.eclipse.org/forums/index.php/t/1085178/. Still: https://www.codeaffine.com/2015/11/30/jgit-clone-repository/ – VonC Feb 02 '19 at 23:20