diff --git a/docs/modules/ROOT/pages/grgit-fetch.adoc b/docs/modules/ROOT/pages/grgit-fetch.adoc index c268941e..02071eaa 100644 --- a/docs/modules/ROOT/pages/grgit-fetch.adoc +++ b/docs/modules/ROOT/pages/grgit-fetch.adoc @@ -13,7 +13,7 @@ grgit.fetch() [source, groovy] ---- -grgit.fetch(remote: '', refSpecs: [, ...], prune: , tagMode: ) +grgit.fetch(remote: '', refSpecs: [, ...], prune: , depth: , tagMode: ) ---- [source, groovy] @@ -22,6 +22,7 @@ grgit.fetch { remote = '' refspecs = [, ...] prune = + depth = tagMode = } ---- @@ -43,6 +44,7 @@ The format of a parameter is an optional plus +, followed by the sourc + The remote ref that matches is fetched, and if is not empty string, the local ref that matches it is fast-forwarded using . If the optional plus + is used, the local ref is updated even if it does not result in a fast-forward update. prune:: (`boolean`, default `false`) Before fetching, remove any remote-tracking references that no longer exist on the remote. Tags are not subject to pruning if they are fetched only because of the default tag auto-following or due to a `tagMode` option. However, if tags are fetched due to an explicit refspec, then they are also subject to pruning. +depth: (`Integer`, default `null`) If set, limits fetching to the specified number of commits from the tip each remote branch history tagMode:: (`String`, default `auto`) Must be one of `'auto'`, `'all'`, `'none'`. + `'auto'` - tags that point at objects that are downloaded from the remote repository are fetched and stored locally. diff --git a/grgit-core/src/main/groovy/org/ajoberstar/grgit/operation/FetchOp.groovy b/grgit-core/src/main/groovy/org/ajoberstar/grgit/operation/FetchOp.groovy index 803d8c11..b65a33f4 100644 --- a/grgit-core/src/main/groovy/org/ajoberstar/grgit/operation/FetchOp.groovy +++ b/grgit-core/src/main/groovy/org/ajoberstar/grgit/operation/FetchOp.groovy @@ -35,6 +35,11 @@ class FetchOp implements Callable { */ boolean prune = false + /** + * The depth of the clone. Defaults to full history. + */ + Integer depth = null + /** * How should tags be handled. */ @@ -58,6 +63,7 @@ class FetchOp implements Callable { cmd.refSpecs = refSpecs.collect { new RefSpec(it) } cmd.removeDeletedRefs = prune cmd.tagOpt = tagMode.jgit + if (depth) { cmd.depth = depth } cmd.call() return null } diff --git a/grgit-core/src/test/groovy/org/ajoberstar/grgit/operation/FetchOpSpec.groovy b/grgit-core/src/test/groovy/org/ajoberstar/grgit/operation/FetchOpSpec.groovy index 7269dd9d..1b9e9355 100644 --- a/grgit-core/src/test/groovy/org/ajoberstar/grgit/operation/FetchOpSpec.groovy +++ b/grgit-core/src/test/groovy/org/ajoberstar/grgit/operation/FetchOpSpec.groovy @@ -3,9 +3,7 @@ package org.ajoberstar.grgit.operation import org.ajoberstar.grgit.Grgit import org.ajoberstar.grgit.fixtures.GitTestUtil import org.ajoberstar.grgit.fixtures.MultiGitOpSpec -import org.ajoberstar.grgit.operation.FetchOp.TagMode import org.eclipse.jgit.api.errors.GitAPIException - import spock.lang.Unroll class FetchOpSpec extends MultiGitOpSpec { @@ -106,4 +104,16 @@ class FetchOpSpec extends MultiGitOpSpec { 'refs/remotes/origin/master', 'refs/remotes/origin/my-branch'] } + + def 'fetch with depth does a shallow fetch'() { + given: + def shallowGrgit = init('shallow') + shallowGrgit.remote.add(name: 'origin', url: remoteGrgit.repository.rootDir.toURI()) + when: + shallowGrgit.fetch(remote: 'origin', depth: 1) + shallowGrgit.checkout(branch: 'master', createBranch: true, startPoint: 'origin/master') + then: + shallowGrgit.head().id == remoteGrgit.resolve.toCommit('master').id + shallowGrgit.head().parentIds.isEmpty() + } }