Skip to content
This repository was archived by the owner on Sep 3, 2025. It is now read-only.

Commit 28cf8c8

Browse files
authored
Merge pull request #104 from ajoberstar/shallow
Support shallow clones/fetches
2 parents 6791131 + 73370cf commit 28cf8c8

File tree

12 files changed

+94
-21
lines changed

12 files changed

+94
-21
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ gitPublish {
5050
5151
// branch will be created if it doesn't exist
5252
branch = 'gh-pages'
53+
54+
// if set, a shallow clone will be performed instead of pulling all history
55+
fetchDepth = null
5356
5457
// generally, you don't need to touch this
5558
repoDir = file("$buildDir/somewhereelse") // defaults to $buildDir/gitPublish

gradle.lockfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
cglib:cglib-nodep:3.3.0=compatTestCompileClasspath,compatTestRuntimeClasspath
55
com.googlecode.javaewah:JavaEWAH:1.1.13=compatTestCompileClasspath,compatTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
66
net.bytebuddy:byte-buddy:1.11.0=compatTestCompileClasspath,compatTestRuntimeClasspath
7-
org.ajoberstar.grgit:grgit-core:5.0.0=compatTestCompileClasspath,compatTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
8-
org.ajoberstar.grgit:grgit-gradle:5.0.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
7+
org.ajoberstar.grgit:grgit-core:5.2.0=compatTestCompileClasspath,compatTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
8+
org.ajoberstar.grgit:grgit-gradle:5.2.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
99
org.apiguardian:apiguardian-api:1.1.0=compatTestCompileClasspath,compatTestRuntimeClasspath
1010
org.assertj:assertj-core:3.16.1=compatTestCompileClasspath,compatTestRuntimeClasspath
11-
org.codehaus.groovy:groovy:3.0.9=compatTestCompileClasspath,compatTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
12-
org.eclipse.jgit:org.eclipse.jgit:6.0.0.202111291000-r=compatTestCompileClasspath,compatTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
11+
org.codehaus.groovy:groovy:3.0.17=compatTestCompileClasspath,compatTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
12+
org.eclipse.jgit:org.eclipse.jgit:6.5.0.202303070854-r=compatTestCompileClasspath,compatTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
1313
org.hamcrest:hamcrest:2.2=compatTestCompileClasspath,compatTestRuntimeClasspath
1414
org.jetbrains:annotations:20.1.0=compatTestCompileClasspath,compatTestRuntimeClasspath
1515
org.junit.platform:junit-platform-commons:1.7.2=compatTestCompileClasspath,compatTestRuntimeClasspath

gradle/wrapper/gradle-wrapper.jar

2.2 KB
Binary file not shown.
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
4+
networkTimeout=10000
45
zipStoreBase=GRADLE_USER_HOME
56
zipStorePath=wrapper/dists

gradlew

Lines changed: 18 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gradlew.bat

Lines changed: 9 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compatTest/groovy/org/ajoberstar/gradle/git/publish/BaseCompatTest.groovy

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,41 @@ gitPublish {
9292
remoteFile('content.txt').text == 'published content here'
9393
}
9494

95+
def 'publish with fetchDepth 1 adds to history if branch already exists'() {
96+
given:
97+
remote.checkout(branch: 'gh-pages')
98+
remoteFile('index.md') << 'And has great content'
99+
remote.add(patterns: ['.'])
100+
remote.commit(message: 'second pages commit')
101+
remote.checkout(branch: 'master')
102+
103+
projectFile('src/content.txt') << 'published content here'
104+
105+
buildFile << """
106+
plugins {
107+
id 'org.ajoberstar.git-publish'
108+
}
109+
110+
gitPublish {
111+
repoUri = '${remote.repository.rootDir.toURI()}'
112+
branch = 'gh-pages'
113+
fetchDepth = 1
114+
contents.from 'src'
115+
}
116+
"""
117+
when:
118+
def result = build()
119+
and:
120+
remote.checkout(branch: 'gh-pages')
121+
then:
122+
result.task(':gitPublishPush').outcome == TaskOutcome.SUCCESS
123+
remote.log().size() == 3
124+
remoteFile('content.txt').text == 'published content here'
125+
def working = Grgit.open(dir: "${projectDir}/build/gitPublish/main")
126+
working.head().parentIds.collect { working.resolve.toCommit(it).parentIds == [] }
127+
working.close()
128+
}
129+
95130
def 'reset pulls from reference repo if available before pulling from remote'() {
96131
given:
97132
def referenceDir = new File(tempDir, 'reference')
@@ -339,7 +374,6 @@ task hello {
339374
notThrown(UnexpectedBuildFailure)
340375
}
341376

342-
@IgnoreIf({ Integer.parseInt(System.properties['compat.gradle.version'].split('\\.')[0]) < 5 })
343377
def 'commit message can be changed'() {
344378
given:
345379
projectFile('src/content.txt') << 'published content here'

src/main/java/org/ajoberstar/gradle/git/publish/GitPublication.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class GitPublication implements Named {
1616
private final Property<String> repoUri;
1717
private final Property<String> referenceRepoUri;
1818
private final Property<String> branch;
19+
private final Property<Integer> fetchDepth;
1920
private final Property<String> commitMessage;
2021
private final Property<Boolean> sign;
2122
private final CopySpec contents;
@@ -27,6 +28,7 @@ public GitPublication(String name, Project project, ObjectFactory objectFactory)
2728
this.repoUri = objectFactory.property(String.class);
2829
this.referenceRepoUri = objectFactory.property(String.class);
2930
this.branch = objectFactory.property(String.class);
31+
this.fetchDepth = objectFactory.property(Integer.class);
3032
this.commitMessage = objectFactory.property(String.class);
3133
this.sign = objectFactory.property(Boolean.class);
3234

@@ -56,6 +58,10 @@ public Property<String> getBranch() {
5658
return branch;
5759
}
5860

61+
public Property<Integer> getFetchDepth() {
62+
return fetchDepth;
63+
}
64+
5965
public Property<String> getCommitMessage() {
6066
return commitMessage;
6167
}

src/main/java/org/ajoberstar/gradle/git/publish/GitPublishExtension.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public Property<String> getBranch() {
4343
return publications.getByName("main").getBranch();
4444
}
4545

46+
public Property<Integer> getFetchDepth() {
47+
return publications.getByName("main").getFetchDepth();
48+
}
49+
4650
public Property<String> getCommitMessage() {
4751
return publications.getByName("main").getCommitMessage();
4852
}

src/main/java/org/ajoberstar/gradle/git/publish/GitPublishPlugin.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ private TaskProvider<GitPublishReset> createResetTask(Project project, GitPublic
7373
task.getRepoUri().set(publication.getRepoUri());
7474
task.getReferenceRepoUri().set(publication.getReferenceRepoUri());
7575
task.getBranch().set(publication.getBranch());
76+
task.getFetchDepth().set(publication.getFetchDepth());
7677
task.setPreserve(publication.getPreserve());
7778
});
7879
}

0 commit comments

Comments
 (0)