Skip to content

Commit

Permalink
Merge pull request #104 from ajoberstar/shallow
Browse files Browse the repository at this point in the history
Support shallow clones/fetches
  • Loading branch information
ajoberstar committed Apr 22, 2023
2 parents 6791131 + 73370cf commit 28cf8c8
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 21 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ gitPublish {
// branch will be created if it doesn't exist
branch = 'gh-pages'
// if set, a shallow clone will be performed instead of pulling all history
fetchDepth = null
// generally, you don't need to touch this
repoDir = file("$buildDir/somewhereelse") // defaults to $buildDir/gitPublish
Expand Down
8 changes: 4 additions & 4 deletions gradle.lockfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
cglib:cglib-nodep:3.3.0=compatTestCompileClasspath,compatTestRuntimeClasspath
com.googlecode.javaewah:JavaEWAH:1.1.13=compatTestCompileClasspath,compatTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
net.bytebuddy:byte-buddy:1.11.0=compatTestCompileClasspath,compatTestRuntimeClasspath
org.ajoberstar.grgit:grgit-core:5.0.0=compatTestCompileClasspath,compatTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.ajoberstar.grgit:grgit-gradle:5.0.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.ajoberstar.grgit:grgit-core:5.2.0=compatTestCompileClasspath,compatTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.ajoberstar.grgit:grgit-gradle:5.2.0=compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.apiguardian:apiguardian-api:1.1.0=compatTestCompileClasspath,compatTestRuntimeClasspath
org.assertj:assertj-core:3.16.1=compatTestCompileClasspath,compatTestRuntimeClasspath
org.codehaus.groovy:groovy:3.0.9=compatTestCompileClasspath,compatTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.eclipse.jgit:org.eclipse.jgit:6.0.0.202111291000-r=compatTestCompileClasspath,compatTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
org.codehaus.groovy:groovy:3.0.17=compatTestCompileClasspath,compatTestRuntimeClasspath,compileClasspath,runtimeClasspath,testCompileClasspath,testRuntimeClasspath
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
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
25 changes: 18 additions & 7 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,13 +80,10 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -143,12 +140,16 @@ fi
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -193,6 +194,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand All @@ -205,6 +210,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
15 changes: 9 additions & 6 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
Expand All @@ -25,7 +25,8 @@
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand All @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand Down Expand Up @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,41 @@ gitPublish {
remoteFile('content.txt').text == 'published content here'
}

def 'publish with fetchDepth 1 adds to history if branch already exists'() {
given:
remote.checkout(branch: 'gh-pages')
remoteFile('index.md') << 'And has great content'
remote.add(patterns: ['.'])
remote.commit(message: 'second pages commit')
remote.checkout(branch: 'master')

projectFile('src/content.txt') << 'published content here'

buildFile << """
plugins {
id 'org.ajoberstar.git-publish'
}
gitPublish {
repoUri = '${remote.repository.rootDir.toURI()}'
branch = 'gh-pages'
fetchDepth = 1
contents.from 'src'
}
"""
when:
def result = build()
and:
remote.checkout(branch: 'gh-pages')
then:
result.task(':gitPublishPush').outcome == TaskOutcome.SUCCESS
remote.log().size() == 3
remoteFile('content.txt').text == 'published content here'
def working = Grgit.open(dir: "${projectDir}/build/gitPublish/main")
working.head().parentIds.collect { working.resolve.toCommit(it).parentIds == [] }
working.close()
}

def 'reset pulls from reference repo if available before pulling from remote'() {
given:
def referenceDir = new File(tempDir, 'reference')
Expand Down Expand Up @@ -339,7 +374,6 @@ task hello {
notThrown(UnexpectedBuildFailure)
}

@IgnoreIf({ Integer.parseInt(System.properties['compat.gradle.version'].split('\\.')[0]) < 5 })
def 'commit message can be changed'() {
given:
projectFile('src/content.txt') << 'published content here'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class GitPublication implements Named {
private final Property<String> repoUri;
private final Property<String> referenceRepoUri;
private final Property<String> branch;
private final Property<Integer> fetchDepth;
private final Property<String> commitMessage;
private final Property<Boolean> sign;
private final CopySpec contents;
Expand All @@ -27,6 +28,7 @@ public GitPublication(String name, Project project, ObjectFactory objectFactory)
this.repoUri = objectFactory.property(String.class);
this.referenceRepoUri = objectFactory.property(String.class);
this.branch = objectFactory.property(String.class);
this.fetchDepth = objectFactory.property(Integer.class);
this.commitMessage = objectFactory.property(String.class);
this.sign = objectFactory.property(Boolean.class);

Expand Down Expand Up @@ -56,6 +58,10 @@ public Property<String> getBranch() {
return branch;
}

public Property<Integer> getFetchDepth() {
return fetchDepth;
}

public Property<String> getCommitMessage() {
return commitMessage;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public Property<String> getBranch() {
return publications.getByName("main").getBranch();
}

public Property<Integer> getFetchDepth() {
return publications.getByName("main").getFetchDepth();
}

public Property<String> getCommitMessage() {
return publications.getByName("main").getCommitMessage();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ private TaskProvider<GitPublishReset> createResetTask(Project project, GitPublic
task.getRepoUri().set(publication.getRepoUri());
task.getReferenceRepoUri().set(publication.getReferenceRepoUri());
task.getBranch().set(publication.getBranch());
task.getFetchDepth().set(publication.getFetchDepth());
task.setPreserve(publication.getPreserve());
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class GitPublishReset extends DefaultTask {
private final Property<String> repoUri;
private final Property<String> referenceRepoUri;
private final Property<String> branch;
private final Property<Integer> fetchDepth;
private PatternFilterable preserve;
private final ObjectFactory objectFactory;

Expand All @@ -37,6 +38,7 @@ public GitPublishReset(ObjectFactory objectFactory) {
this.repoUri = objectFactory.property(String.class);
this.referenceRepoUri = objectFactory.property(String.class);
this.branch = objectFactory.property(String.class);
this.fetchDepth = objectFactory.property(Integer.class);
this.objectFactory = objectFactory;
}

Expand All @@ -60,6 +62,12 @@ public Property<String> getBranch() {
return branch;
}

@Input
@Optional
public Property<Integer> getFetchDepth() {
return fetchDepth;
}

@Internal
public PatternFilterable getPreserve() {
return preserve;
Expand Down Expand Up @@ -118,6 +126,7 @@ public void reset() throws IOException {
git.fetch(op -> {
op.setRefSpecs(Arrays.asList(String.format("+refs/heads/%s:refs/remotes/reference/%s", pubBranch, pubBranch)));
op.setTagMode("none");
op.setDepth(getFetchDepth().getOrNull());
});
}
}
Expand All @@ -136,6 +145,7 @@ public void reset() throws IOException {
getLogger().info("Fetching from remote repo: " + repoUri.get());
op.setRefSpecs(Arrays.asList(String.format("+refs/heads/%s:refs/remotes/origin/%s", pubBranch, pubBranch)));
op.setTagMode("none");
op.setDepth(getFetchDepth().getOrNull());
});

// make sure local branch exists
Expand Down
4 changes: 2 additions & 2 deletions 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

0 comments on commit 28cf8c8

Please sign in to comment.