Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to specify depth for shallow clone #384

Merged
merged 1 commit into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion grgit-core/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ net.bytebuddy:byte-buddy:1.12.10=testCompileClasspath,testRuntimeClasspath
org.apiguardian:apiguardian-api:1.1.2=testCompileClasspath
org.assertj:assertj-core:3.23.1=testCompileClasspath,testRuntimeClasspath
org.codehaus.groovy:groovy:3.0.12=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.eclipse.jgit:org.eclipse.jgit:6.2.0.202206071550-r=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.eclipse.jgit:org.eclipse.jgit:6.4.0.202211300538-r=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.hamcrest:hamcrest:2.2=testCompileClasspath,testRuntimeClasspath
org.jetbrains:annotations:20.1.0=testCompileClasspath,testRuntimeClasspath
org.junit.jupiter:junit-jupiter-api:5.9.0=testCompileClasspath,testRuntimeClasspath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ class CloneOp implements Callable<Grgit> {
*/
String refToCheckout

/**
* The depth of the clone. Defaults to full history.
*/
Integer depth = null

/**
* The username and credentials to use when checking out the
* repository and for subsequent remote operations on the
Expand All @@ -89,6 +94,9 @@ class CloneOp implements Callable<Grgit> {
cmd.remote = remote
cmd.bare = bare
cmd.noCheckout = !checkout
if (depth != null) {
cmd.depth = depth
}
if (refToCheckout) { cmd.branch = refToCheckout }
if (all) { cmd.cloneAllBranches = all }
if (!branches.isEmpty()) cmd.branchesToClone = branches
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@ class CloneOpSpec extends MultiGitOpSpec {
GitTestUtil.branches(grgit).findAll(localBranchesFilter).collect(lastName) == ['master']
}

def 'clone with all false and 1 depth'() {
when:
def grgit = Grgit.clone(dir: repoDir, uri: remoteUri, all: false, depth: 1)
then:
grgit.head().id == remoteGrgit.resolve.toCommit('master').id
grgit.head().parentIds.isEmpty()
GitTestUtil.branches(grgit).findAll(localBranchesFilter).collect(lastName) == ['master']
}

def 'cloned repo can be deleted'() {
given:
def grgit = Grgit.clone(dir: repoDir, uri: remoteUri, refToCheckout: 'refs/heads/branch2')
Expand Down
2 changes: 1 addition & 1 deletion grgit-gradle/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ net.bytebuddy:byte-buddy:1.11.0=compatTestCompileClasspath,compatTestRuntimeClas
org.apiguardian:apiguardian-api:1.1.0=compatTestCompileClasspath,compatTestRuntimeClasspath
org.assertj:assertj-core:3.16.1=compatTestCompileClasspath,compatTestRuntimeClasspath
org.codehaus.groovy:groovy:3.0.12=compatTestCompileClasspath,compatTestRuntimeClasspath
org.eclipse.jgit:org.eclipse.jgit:6.2.0.202206071550-r=compatTestCompileClasspath,compatTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.eclipse.jgit:org.eclipse.jgit:6.4.0.202211300538-r=compatTestCompileClasspath,compatTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.hamcrest:hamcrest:2.2=compatTestCompileClasspath,compatTestRuntimeClasspath
org.jetbrains:annotations:20.1.0=compatTestCompileClasspath,compatTestRuntimeClasspath
org.junit.platform:junit-platform-commons:1.7.2=compatTestCompileClasspath,compatTestRuntimeClasspath
Expand Down