Skip to content

Commit

Permalink
Merge pull request #113 from ajoberstar/fixes
Browse files Browse the repository at this point in the history
Attempt fix to #112
  • Loading branch information
ajoberstar authored Nov 23, 2024
2 parents e9b625b + af99ce3 commit 8b81ec4
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 56 deletions.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import org.gradle.testkit.runner.UnexpectedBuildFailure
import spock.lang.Specification
import spock.lang.TempDir

import java.rmi.UnexpectedException

class BaseCompatTest extends Specification {
@TempDir File tempDir
File projectDir
Expand Down Expand Up @@ -125,7 +127,7 @@ gitPublish {
working.close()
}

def 'reset pulls from reference repo if available before pulling from remote'() {
def 'reset uses reference repo objects if available before pulling from remote'() {
given:
def referenceDir = new File(tempDir, 'reference')
def reference = Grgit.clone(dir: referenceDir, uri: repoPath(remote))
Expand Down Expand Up @@ -157,7 +159,6 @@ gitPublish {
remote.checkout(branch: 'gh-pages')
then:
result.task(':gitPublishPush').outcome == TaskOutcome.SUCCESS
result.output.contains('gh-pages -> reference/gh-pages')
remote.log().size() == 2
remoteFile('content.txt').text == 'published content here'
!remoteFile('newFile.txt').exists()
Expand Down Expand Up @@ -326,7 +327,6 @@ gitPublish {
}

def working = Grgit.clone(dir: "${projectDir}/build/gitPublish", uri: badRemote.repository.rootDir.toURI())
working.checkout(branch: 'gh-pages', startPoint: 'origin/master', createBranch: true)
working.close()

new File(projectDir, 'content.txt') << 'published content here'
Expand All @@ -348,9 +348,11 @@ gitPublish {
and:
remote.checkout(branch: 'gh-pages')
working = Grgit.open(dir: "${projectDir}/build/gitPublish")
working.checkout(branch: 'master')
then:
result.task(':gitPublishPush').outcome == TaskOutcome.SUCCESS
remote.log().size() == 2
working.head().fullMessage == 'bad first commit'
}

def 'when no git publish tasks are run, build completes successfully'() {
Expand Down Expand Up @@ -420,10 +422,15 @@ gitPublish {
}
"""
when:
def result = buildAndFail()
def result = buildOrFail()

then:
result.output.contains("gpg: signing failed: No secret key")
def newCommit = remote.resolve.toCommit("gh-pages").id
def remoteGitDir = "${remote.repository.rootDir}/.git"
def proc = "git --git-dir ${remoteGitDir} cat-file -p ${newCommit}".execute()
def latestCommit = proc.in.text
// either it will work and sign or the key will be missing and it won't be able to
latestCommit.contains("gpgsig") || result.output.contains("gpg: signing failed: No secret key")
}

def 'can deactivate signing'() {
Expand Down Expand Up @@ -451,6 +458,12 @@ gitPublish {

then:
result.task(':gitPublishPush').outcome == TaskOutcome.SUCCESS

def newCommit = remote.resolve.toCommit("gh-pages").id
def remoteGitDir = "${remote.repository.rootDir}/.git"
def proc = "git --git-dir ${remoteGitDir} cat-file -p ${newCommit}".execute()
def latestCommit = proc.in.text
!latestCommit.contains('gpgsign')
}

private BuildResult build(String... args = ['gitPublishPush', '--stacktrace', '--configuration-cache']) {
Expand All @@ -461,6 +474,14 @@ gitPublish {
return runner(args).buildAndFail()
}

private BuildResult buildOrFail(String... args = ['gitPublishPush', '--stacktrace', '--configuration-cache']) {
try {
return runner(args).build()
} catch (UnexpectedBuildFailure e) {
return e.buildResult
}
}

private GradleRunner runner(String... args) {
return GradleRunner.create()
.withGradleVersion(System.properties['compat.gradle.version'])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.ajoberstar.gradle.git.publish;

import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;

import javax.inject.Inject;
Expand All @@ -27,6 +28,7 @@ public interface Params extends ValueSourceParameters {
spec.executable("git");
spec.setArgs(getParameters().getGitArguments().get());
spec.setStandardOutput(output);
spec.setErrorOutput(OutputStream.nullOutputStream());
});
return output.toString(StandardCharsets.UTF_8).trim();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package org.ajoberstar.gradle.git.publish;

import java.nio.file.Path;

import org.ajoberstar.gradle.git.publish.tasks.GitPublishCommit;
import org.ajoberstar.gradle.git.publish.tasks.GitPublishPush;
import org.ajoberstar.gradle.git.publish.tasks.GitPublishReset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import javax.inject.Inject;

Expand Down Expand Up @@ -69,7 +72,7 @@ public void reset() throws IOException {
// initialize git repo
if (!new File(repoDir, ".git").exists()) {
getExecOperations().exec(spec -> {
spec.commandLine("git", "init");
spec.commandLine("git", "init", "--initial-branch=" + pubBranch);
spec.workingDir(repoDir);
spec.setStandardOutput(OutputStream.nullOutputStream());
});
Expand All @@ -91,51 +94,21 @@ public void reset() throws IOException {
});
}

// set reference
// set alternate object store if reference used
if (getReferenceRepoUri().isPresent()) {
try {
getExecOperations().exec(spec -> {
spec.commandLine("git", "remote", "add", "reference", getReferenceRepoUri().get());
spec.workingDir(repoDir);
spec.setStandardOutput(OutputStream.nullOutputStream());
spec.setErrorOutput(OutputStream.nullOutputStream());
});
} catch (Exception e) {
getExecOperations().exec(spec -> {
spec.commandLine("git", "remote", "set-url", "reference", getReferenceRepoUri().get());
spec.workingDir(repoDir);
spec.setStandardOutput(OutputStream.nullOutputStream());
});
}

// check reference for branch
boolean referenceHasBranch;
try {
getExecOperations().exec(spec -> {
spec.commandLine("git", "ls-remote", "--exit-code", "reference", pubBranch);
spec.workingDir(repoDir);
spec.setStandardOutput(OutputStream.nullOutputStream());
});
referenceHasBranch = true;
} catch (Exception e) {
referenceHasBranch = false;
}

if (referenceHasBranch) {
// get local branch reset to remote state
getExecOperations().exec(spec -> {
var refSpec = String.format("+refs/heads/%s:refs/remotes/reference/%s", pubBranch, pubBranch);

spec.executable("git");
spec.args("fetch");
if (getFetchDepth().isPresent()) {
spec.args("--depth", getFetchDepth().get());
}
spec.args("reference", refSpec);

spec.workingDir(repoDir);
spec.setStandardOutput(OutputStream.nullOutputStream());
});
Path repoObjectsPath = repoDir.toPath().resolve(".git").resolve("objects");
Path alternatesPath = repoObjectsPath.resolve("info").resolve("alternates");

Path referenceRepoPath = Path.of(getReferenceRepoUri().get());

Path referenceRepoObjectsPath = referenceRepoPath.resolve(".git").resolve("objects");
Path referenceBareRepoObjectsPath = referenceRepoPath.resolve("objects");
if (Files.exists(referenceRepoObjectsPath)) {
Files.writeString(alternatesPath, referenceRepoObjectsPath + "\n", StandardCharsets.UTF_8);
} else if (Files.exists(referenceBareRepoObjectsPath)) {
Files.writeString(alternatesPath, referenceBareRepoObjectsPath + "\n", StandardCharsets.UTF_8);
} else {
getLogger().warn("Reference repo doesn't seem to have an objects database: {}", referenceRepoPath);
}
}

Expand All @@ -146,6 +119,7 @@ public void reset() throws IOException {
spec.commandLine("git", "ls-remote", "--exit-code", "origin", pubBranch);
spec.workingDir(repoDir);
spec.setStandardOutput(OutputStream.nullOutputStream());
spec.setErrorOutput(OutputStream.nullOutputStream());
});
hasBranch = true;
} catch (Exception e) {
Expand All @@ -162,6 +136,7 @@ public void reset() throws IOException {
if (getFetchDepth().isPresent()) {
spec.args("--depth", getFetchDepth().get());
}
spec.args("--no-tags");
spec.args("origin", refSpec);

spec.workingDir(repoDir);
Expand Down
6 changes: 3 additions & 3 deletions stutter.lockfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# DO NOT MODIFY: Generated by Stutter plugin.
java11=7.0.2,7.6.4,8.0.2,8.10.2
java17=7.3.3,7.6.4,8.0.2,8.10.2
java21=8.4,8.10.2
java11=7.0.2,7.6.4,8.0.2,8.11.1
java17=7.3.3,7.6.4,8.0.2,8.11.1
java21=8.4,8.11.1

0 comments on commit 8b81ec4

Please sign in to comment.