diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0f27d03d..6da079b4 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -7,23 +7,20 @@ jobs: ci: runs-on: ubuntu-latest env: - GRADLE_OPTS: -Dorg.gradle.java.installations.fromEnv=JAVA_HOME_8_x64,JAVA_HOME_11_x64,JAVA_HOME_17_x64 + GRADLE_OPTS: -Dorg.gradle.java.installations.fromEnv=JAVA_HOME_11_x64,JAVA_HOME_17_x64 steps: - name: Checkout repo - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 0 - - name: Setup Java 11 - uses: actions/setup-java@v2 + - name: Setup Java + uses: actions/setup-java@v3 with: distribution: temurin - java-version: 11 - - name: Setup Java 17 - uses: actions/setup-java@v2 - with: - distribution: temurin - java-version: 17 + java-version: | + 11 + 17 - name: Validate Gradle Wrapper uses: gradle/wrapper-validation-action@v1 @@ -31,3 +28,6 @@ jobs: uses: gradle/gradle-build-action@v2 - name: Gradle check run: ./gradlew check --continue + env: + ORG_GRADLE_PROJECT_signingKey: ${{ secrets.PGP_SIGNING_KEY }} + ORG_GRADLE_PROJECT_signingPassphrase: ${{ secrets.PGP_SIGNING_PASSPHRASE }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 2bd83a84..8c1786b7 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -7,19 +7,17 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout repo - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 0 - - name: Setup Java 11 - uses: actions/setup-java@v2 - with: - distribution: zulu - java-version: 11 + - name: Setup Java 17 - uses: actions/setup-java@v2 + uses: actions/setup-java@v3 with: - distribution: zulu - java-version: 17 + distribution: temurin + java-version: | + 11 + 17 - name: Setup Gradle uses: gradle/gradle-build-action@v2 diff --git a/README.md b/README.md index 2e594e16..a6628e7c 100644 --- a/README.md +++ b/README.md @@ -65,18 +65,15 @@ plugins { id 'org.ajoberstar.grgit.service' version '' } -tasks.register("describe", DescribeTask) { - service = grgitService.service -} +tasks.register("describe", DescribeTask, grgitService.service) class DescribeTask extends DefaultTask { - @Input - final Property service + private final Provider service @Inject - DoStuffTask(ObjectFactory objectFactory) { - this.service = objectFactory.property(GrgitService.class); - usesService(this.service); + DescribeTask(Provider service) { + this.service = service + usesService(service) } @TaskAction diff --git a/docs/modules/ROOT/pages/grgit-clone.adoc b/docs/modules/ROOT/pages/grgit-clone.adoc index fbb7a9f2..0f5e68ee 100644 --- a/docs/modules/ROOT/pages/grgit-clone.adoc +++ b/docs/modules/ROOT/pages/grgit-clone.adoc @@ -10,7 +10,7 @@ grgit-clone - Clone a repository into a new directory ---- Grgit.clone(dir: , uri: , remote: , all: , bare: , branches: , checkout: , - refToCheckout: , credentials: ) + refToCheckout: , depth: , credentials: ) ---- [source, groovy] @@ -24,6 +24,7 @@ Grgit.clone { branches = checkout = refToCheckout = + depth = credentials = } ---- @@ -48,6 +49,7 @@ bare:: (`boolean`, default `false`) Create a bare repository. branches:: (`List`, `[]`) Select full refs to use with `all = false`. checkout:: (`boolean`, default `true`) Set to `false` to skip checking out a `HEAD`. refToCheckout:: (`String`, default `null`) Instead of pointing the newly created `HEAD` to the branch pointed to by the cloned repository’s `HEAD`, point to `` branch instead. In a non-bare repository, this is the branch that will be checked out. This can also take tags and detaches the `HEAD` at that commit in the resulting repository. +depth:: (`Integer`, default `null`) If set, does a shallow clone to the specified depth credentials:: (`Credentials`, default `null`) An instance of link:https://github.com/ajoberstar/grgit/blob/{page-component-version}/grgit-core/src/main/groovy/org/ajoberstar/grgit/Credentials.groovy[Credentials] containing username/password to be used in operations that require authentication. See xref:grgit-authentication.adoc[grgit-authentication] for preferred ways to configure this. == Examples diff --git a/grgit-core/gradle.lockfile b/grgit-core/gradle.lockfile index 5aa7501f..2d73ba9c 100644 --- a/grgit-core/gradle.lockfile +++ b/grgit-core/gradle.lockfile @@ -6,21 +6,21 @@ com.googlecode.javaewah:JavaEWAH:1.1.13=compileClasspath,runtimeClasspath,testCo 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.codehaus.groovy:groovy:3.0.17=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath +org.eclipse.jgit:org.eclipse.jgit:6.5.0.202303070854-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 -org.junit.platform:junit-platform-commons:1.9.0=testCompileClasspath,testRuntimeClasspath -org.junit.platform:junit-platform-engine:1.9.0=testCompileClasspath,testRuntimeClasspath -org.junit.platform:junit-platform-launcher:1.9.0=testCompileClasspath,testRuntimeClasspath -org.junit.platform:junit-platform-testkit:1.9.0=testCompileClasspath,testRuntimeClasspath -org.junit:junit-bom:5.9.0=testCompileClasspath,testRuntimeClasspath +org.junit.jupiter:junit-jupiter-api:5.9.2=testCompileClasspath,testRuntimeClasspath +org.junit.platform:junit-platform-commons:1.9.2=testCompileClasspath,testRuntimeClasspath +org.junit.platform:junit-platform-engine:1.9.2=testCompileClasspath,testRuntimeClasspath +org.junit.platform:junit-platform-launcher:1.9.2=testCompileClasspath,testRuntimeClasspath +org.junit.platform:junit-platform-testkit:1.9.2=testCompileClasspath,testRuntimeClasspath +org.junit:junit-bom:5.9.2=testCompileClasspath,testRuntimeClasspath org.objenesis:objenesis:3.2=testCompileClasspath,testRuntimeClasspath org.opentest4j:opentest4j:1.2.0=testCompileClasspath,testRuntimeClasspath org.ow2.asm:asm:9.1=testCompileClasspath,testRuntimeClasspath org.slf4j:slf4j-api:1.7.30=compileClasspath,runtimeClasspath -org.slf4j:slf4j-api:2.0.0-beta1=testCompileClasspath,testRuntimeClasspath -org.slf4j:slf4j-simple:2.0.0-beta1=testRuntimeClasspath +org.slf4j:slf4j-api:2.0.7=testCompileClasspath,testRuntimeClasspath +org.slf4j:slf4j-simple:2.0.7=testRuntimeClasspath org.spockframework:spock-core:2.0-groovy-3.0=testCompileClasspath,testRuntimeClasspath empty= diff --git a/grgit-core/src/main/groovy/org/ajoberstar/grgit/operation/CloneOp.groovy b/grgit-core/src/main/groovy/org/ajoberstar/grgit/operation/CloneOp.groovy index 565719f3..74cdbd6e 100644 --- a/grgit-core/src/main/groovy/org/ajoberstar/grgit/operation/CloneOp.groovy +++ b/grgit-core/src/main/groovy/org/ajoberstar/grgit/operation/CloneOp.groovy @@ -67,6 +67,11 @@ class CloneOp implements Callable { */ 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 @@ -89,6 +94,9 @@ class CloneOp implements Callable { 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 diff --git a/grgit-core/src/test/groovy/org/ajoberstar/grgit/operation/CloneOpSpec.groovy b/grgit-core/src/test/groovy/org/ajoberstar/grgit/operation/CloneOpSpec.groovy index 52936645..787213df 100644 --- a/grgit-core/src/test/groovy/org/ajoberstar/grgit/operation/CloneOpSpec.groovy +++ b/grgit-core/src/test/groovy/org/ajoberstar/grgit/operation/CloneOpSpec.groovy @@ -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') diff --git a/grgit-core/src/test/groovy/org/ajoberstar/grgit/operation/LogOpSpec.groovy b/grgit-core/src/test/groovy/org/ajoberstar/grgit/operation/LogOpSpec.groovy index b8e644e4..ad6d2cfd 100644 --- a/grgit-core/src/test/groovy/org/ajoberstar/grgit/operation/LogOpSpec.groovy +++ b/grgit-core/src/test/groovy/org/ajoberstar/grgit/operation/LogOpSpec.groovy @@ -47,7 +47,7 @@ class LogOpSpec extends SimpleGitOpSpec { def 'log with no arguments returns all commits'() { expect: - grgit.log() == [5, 4, 3, 1, 2, 0].collect(intToCommit) + grgit.log() in [[5, 4, 3, 2, 1, 0], [5, 4, 3, 1, 2, 0]]*.collect(intToCommit) } def 'log with max commits returns that number of commits'() { @@ -57,7 +57,7 @@ class LogOpSpec extends SimpleGitOpSpec { def 'log with skip commits does not return the first x commits'() { expect: - grgit.log(skipCommits:2) == [3, 1, 2, 0].collect(intToCommit) + grgit.log(skipCommits:2) in [[3, 2, 1, 0], [3, 1, 2, 0]]*.collect(intToCommit) } def 'log with range returns only the commits in that range'() { diff --git a/grgit-gradle/build.gradle.kts b/grgit-gradle/build.gradle.kts index c897f2e7..7aec50f3 100644 --- a/grgit-gradle/build.gradle.kts +++ b/grgit-gradle/build.gradle.kts @@ -79,3 +79,11 @@ gradlePlugin { } } } + +tasks.withType { + if (name.startsWith("compatTest")) { + dependsOn(tasks.named("publishToMavenLocal")) + dependsOn(project(":grgit-core").tasks.named("publishToMavenLocal")) + systemProperty("compat.plugin.version", project.version.toString()) + } +} diff --git a/grgit-gradle/gradle.lockfile b/grgit-gradle/gradle.lockfile index 519da633..667fa39b 100644 --- a/grgit-gradle/gradle.lockfile +++ b/grgit-gradle/gradle.lockfile @@ -6,8 +6,8 @@ com.googlecode.javaewah:JavaEWAH:1.1.13=compatTestCompileClasspath,compatTestRun net.bytebuddy:byte-buddy:1.11.0=compatTestCompileClasspath,compatTestRuntimeClasspath 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.codehaus.groovy:groovy:3.0.17=compatTestCompileClasspath,compatTestRuntimeClasspath +org.eclipse.jgit:org.eclipse.jgit:6.5.0.202303070854-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 diff --git a/grgit-gradle/src/compatTest/groovy/org/ajoberstar/grgit/gradle/GrgitPluginCompatTest.groovy b/grgit-gradle/src/compatTest/groovy/org/ajoberstar/grgit/gradle/GrgitPluginCompatTest.groovy index 82b14e59..92225c6c 100644 --- a/grgit-gradle/src/compatTest/groovy/org/ajoberstar/grgit/gradle/GrgitPluginCompatTest.groovy +++ b/grgit-gradle/src/compatTest/groovy/org/ajoberstar/grgit/gradle/GrgitPluginCompatTest.groovy @@ -11,11 +11,25 @@ import spock.lang.TempDir class GrgitPluginCompatTest extends Specification { @TempDir File tempDir File projectDir + File settingsFile File buildFile def setup() { projectDir = new File(tempDir, 'project') + settingsFile = projectFile('settings.gradle') buildFile = projectFile('build.gradle') + + settingsFile << """\ +pluginManagement { + repositories { + mavenCentral() + mavenLocal() + } + plugins { + id 'org.ajoberstar.grgit' version '${System.properties['compat.plugin.version']}\' + } +} +""" } def 'with no repo, plugin sets grgit to null'() { @@ -32,7 +46,7 @@ task doStuff { } ''' when: - def result = build('doStuff', '--configuration-cache') + def result = build('doStuff', '--no-configuration-cache') then: result.task(':doStuff').outcome == TaskOutcome.SUCCESS } @@ -57,7 +71,7 @@ task doStuff { } ''' when: - def result = build('doStuff', '--quiet', '--configuration-cache') + def result = build('doStuff', '--quiet', '--no-configuration-cache') then: result.task(':doStuff').outcome == TaskOutcome.SUCCESS result.output.normalize() == '1.0.0\n' @@ -83,7 +97,7 @@ task doStuff { } ''' when: - def result = build('doStuff', '--info', '--configuration-cache') + def result = build('doStuff', '--info', '--no-configuration-cache') then: result.task(':doStuff').outcome == TaskOutcome.SUCCESS result.output.contains('Closing Git repo') diff --git a/grgit-gradle/src/compatTest/groovy/org/ajoberstar/grgit/gradle/GrgitServicePluginCompatTest.groovy b/grgit-gradle/src/compatTest/groovy/org/ajoberstar/grgit/gradle/GrgitServicePluginCompatTest.groovy index b3206041..2faebefe 100644 --- a/grgit-gradle/src/compatTest/groovy/org/ajoberstar/grgit/gradle/GrgitServicePluginCompatTest.groovy +++ b/grgit-gradle/src/compatTest/groovy/org/ajoberstar/grgit/gradle/GrgitServicePluginCompatTest.groovy @@ -11,29 +11,37 @@ import spock.lang.TempDir class GrgitServicePluginCompatTest extends Specification { @TempDir File tempDir File projectDir + File settingsFile File buildFile def setup() { projectDir = new File(tempDir, 'project') + settingsFile = projectFile('settings.gradle') + settingsFile << '''\ +pluginManagement { + repositories { + mavenCentral() + mavenLocal() + } +} +''' buildFile = projectFile('build.gradle') - buildFile << '''\ + buildFile << """\ import org.ajoberstar.grgit.gradle.GrgitService plugins { - id 'org.ajoberstar.grgit.service' + id 'org.ajoberstar.grgit.service' version '${System.properties['compat.plugin.version']}' } -tasks.register("doStuff", DoStuffTask.class) { - service = grgitService.service -} +tasks.register("doStuff", DoStuffTask, grgitService.service) class DoStuffTask extends DefaultTask { - @Input - final Property service + private final Provider service @Inject - DoStuffTask(ObjectFactory objectFactory) { - this.service = objectFactory.property(GrgitService.class); + DoStuffTask(Provider service) { + this.service = service + usesService(service) } @TaskAction @@ -41,7 +49,7 @@ class DoStuffTask extends DefaultTask { println service.get().grgit.describe() } } -''' +""" } def 'with no repo, accessing service fails'() { @@ -84,7 +92,6 @@ class DoStuffTask extends DefaultTask { private BuildResult build(String... args) { return GradleRunner.create() .withGradleVersion(System.properties['compat.gradle.version']) - .withPluginClasspath() .withProjectDir(projectDir) .forwardOutput() .withArguments((args + '--stacktrace') as String[]) @@ -94,7 +101,6 @@ class DoStuffTask extends DefaultTask { private BuildResult buildAndFail(String... args) { return GradleRunner.create() .withGradleVersion(System.properties['compat.gradle.version']) - .withPluginClasspath() .withProjectDir(projectDir) .forwardOutput() .withArguments((args + '--stacktrace') as String[]) diff --git a/grgit-gradle/src/main/java/org/ajoberstar/grgit/gradle/GrgitServiceExtension.java b/grgit-gradle/src/main/java/org/ajoberstar/grgit/gradle/GrgitServiceExtension.java index 315bd89d..ea864d8a 100644 --- a/grgit-gradle/src/main/java/org/ajoberstar/grgit/gradle/GrgitServiceExtension.java +++ b/grgit-gradle/src/main/java/org/ajoberstar/grgit/gradle/GrgitServiceExtension.java @@ -1,19 +1,15 @@ package org.ajoberstar.grgit.gradle; -import javax.inject.Inject; - -import org.gradle.api.model.ObjectFactory; -import org.gradle.api.provider.Property; +import org.gradle.api.provider.Provider; public class GrgitServiceExtension { - private Property service; + private final Provider service; - @Inject - public GrgitServiceExtension(ObjectFactory objectFactory) { - this.service = objectFactory.property(GrgitService.class); + public GrgitServiceExtension(Provider service) { + this.service = service; } - public Property getService() { + public Provider getService() { return service; } } diff --git a/grgit-gradle/src/main/java/org/ajoberstar/grgit/gradle/GrgitServicePlugin.java b/grgit-gradle/src/main/java/org/ajoberstar/grgit/gradle/GrgitServicePlugin.java index ce4c8617..bb0fac2b 100644 --- a/grgit-gradle/src/main/java/org/ajoberstar/grgit/gradle/GrgitServicePlugin.java +++ b/grgit-gradle/src/main/java/org/ajoberstar/grgit/gradle/GrgitServicePlugin.java @@ -7,14 +7,12 @@ public class GrgitServicePlugin implements Plugin { @Override public void apply(Project project) { - GrgitServiceExtension extension = project.getExtensions().create("grgitService", GrgitServiceExtension.class); - Provider serviceProvider = project.getGradle().getSharedServices().registerIfAbsent("grgit", GrgitService.class, spec -> { spec.getParameters().getCurrentDirectory().set(project.getLayout().getProjectDirectory()); spec.getParameters().getInitIfNotExists().set(false); spec.getMaxParallelUsages().set(1); }); - extension.getService().set(serviceProvider); + project.getExtensions().create("grgitService", GrgitServiceExtension.class, serviceProvider); } } diff --git a/grgit-gradle/stutter.lockfile b/grgit-gradle/stutter.lockfile index e96cc803..7f708003 100644 --- a/grgit-gradle/stutter.lockfile +++ b/grgit-gradle/stutter.lockfile @@ -1,3 +1,3 @@ # DO NOT MODIFY: Generated by Stutter plugin. -java11=7.0.2,7.5.1 -java17=7.3.3,7.5.1 +java11=7.0.2,7.6.1,8.0.2,8.1.1 +java17=7.3.3,7.6.1,8.0.2,8.1.1