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

Updates #386

Merged
merged 12 commits into from
Apr 21, 2023
20 changes: 10 additions & 10 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ 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
- name: Setup Gradle
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 }}
16 changes: 7 additions & 9 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,15 @@ plugins {
id 'org.ajoberstar.grgit.service' version '<version>'
}

tasks.register("describe", DescribeTask) {
service = grgitService.service
}
tasks.register("describe", DescribeTask, grgitService.service)

class DescribeTask extends DefaultTask {
@Input
final Property<GrgitService> service
private final Provider<GrgitService> service

@Inject
DoStuffTask(ObjectFactory objectFactory) {
this.service = objectFactory.property(GrgitService.class);
usesService(this.service);
DescribeTask(Provider<GrgitService> service) {
this.service = service
usesService(service)
}

@TaskAction
Expand Down
4 changes: 3 additions & 1 deletion docs/modules/ROOT/pages/grgit-clone.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ grgit-clone - Clone a repository into a new directory
----
Grgit.clone(dir: <path>, uri: <path or uri>, remote: <name>, all: <boolean>,
bare: <boolean>, branches: <full refs>, checkout: <boolean>,
refToCheckout: <name>, credentials: <credentials>)
refToCheckout: <name>, depth: <integer>, credentials: <credentials>)
----

[source, groovy]
Expand All @@ -24,6 +24,7 @@ Grgit.clone {
branches = <full refs>
checkout = <boolean>
refToCheckout = <name>
depth = <integer>
credentials = <credentials>
}
----
Expand All @@ -48,6 +49,7 @@ bare:: (`boolean`, default `false`) Create a bare repository.
branches:: (`List<String>`, `[]`) 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 `<name>` 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
Expand Down
20 changes: 10 additions & 10 deletions grgit-core/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -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=
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
Original file line number Diff line number Diff line change
Expand Up @@ -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'() {
Expand All @@ -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'() {
Expand Down
8 changes: 8 additions & 0 deletions grgit-gradle/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,11 @@ gradlePlugin {
}
}
}

tasks.withType<Test> {
if (name.startsWith("compatTest")) {
dependsOn(tasks.named("publishToMavenLocal"))
dependsOn(project(":grgit-core").tasks.named("publishToMavenLocal"))
systemProperty("compat.plugin.version", project.version.toString())
}
}
4 changes: 2 additions & 2 deletions grgit-gradle/gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'() {
Expand All @@ -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
}
Expand All @@ -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'
Expand All @@ -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')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,45 @@ 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<GrgitService> service
private final Provider<GrgitService> service

@Inject
DoStuffTask(ObjectFactory objectFactory) {
this.service = objectFactory.property(GrgitService.class);
DoStuffTask(Provider<GrgitService> service) {
this.service = service
usesService(service)
}

@TaskAction
void execute() {
println service.get().grgit.describe()
}
}
'''
"""
}

def 'with no repo, accessing service fails'() {
Expand Down Expand Up @@ -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[])
Expand All @@ -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[])
Expand Down
Original file line number Diff line number Diff line change
@@ -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<GrgitService> service;
private final Provider<GrgitService> service;

@Inject
public GrgitServiceExtension(ObjectFactory objectFactory) {
this.service = objectFactory.property(GrgitService.class);
public GrgitServiceExtension(Provider<GrgitService> service) {
this.service = service;
}

public Property<GrgitService> getService() {
public Provider<GrgitService> getService() {
return service;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@
public class GrgitServicePlugin implements Plugin<Project> {
@Override
public void apply(Project project) {
GrgitServiceExtension extension = project.getExtensions().create("grgitService", GrgitServiceExtension.class);

Provider<GrgitService> 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);
}
}
4 changes: 2 additions & 2 deletions grgit-gradle/stutter.lockfile
Original file line number Diff line number Diff line change
@@ -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