Skip to content

Commit

Permalink
chore: Prevent tests from trying to sign
Browse files Browse the repository at this point in the history
Set git config on test repos to avoid signing commits and tags.
  • Loading branch information
ajoberstar committed Nov 24, 2024
1 parent d88de13 commit 4c901a5
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ public void initRepository() throws IOException, GitAPIException {
.setDirectory(repoDir.toFile())
.call();

var config = git.getRepository().getConfig();
config.setString("user", null, "name", "Some Person");
config.setString("user", null, "email", "[email protected]");
config.setString("commit", null, "gpgSign", "false");
config.setString("tag", null, "gpgSign", "false");
config.save();

var initialBranch = git.getRepository().getBranch();

commit();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ public void setupRepo() throws IOException, GitAPIException {
repoDir = Files.createTempDirectory("repo");
git = Git.init().setDirectory(repoDir.toFile()).call();
initialBranch = git.getRepository().getBranch();

var config = git.getRepository().getConfig();
config.setString("user", null, "name", "Some Person");
config.setString("user", null, "email", "[email protected]");
config.setString("commit", null, "gpgSign", "false");
config.setString("tag", null, "gpgSign", "false");
config.save();
}

@AfterEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class BaseCompatTest extends Specification {

def remoteDir = new File(tempDir, 'remote')
remote = Git.init().setDirectory(remoteDir).call()
Gits.resetConfig(remote);

Gits.repoFile(remote, '.gitignore') << '.gradle/\nbuild/\n'
Gits.repoFile(remote, 'master.txt') << 'contents here'
Expand All @@ -31,6 +32,7 @@ class BaseCompatTest extends Specification {

def remote2Dir = new File(tempDir, 'remote2')
remote2 = Gits.clone(remote2Dir, remote)
Gits.resetConfig(remote2);
}

def 'if no git repo found, version is defaulted'() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class CompositeBuildCompatTest extends Specification {
build2File = projectFile(project2Dir, 'build.gradle')

def git1 = Git.init().setDirectory(project1Dir).call()
Gits.resetConfig(git1);
projectFile(project1Dir, 'settings.gradle') << 'rootProject.name = "project1"'
projectFile(project1Dir, '.gitignore') << '.gradle\nbuild\n'
build1File << '''\
Expand All @@ -45,6 +46,7 @@ task printVersion {
git1.close()

def git2 = Git.init().setDirectory(project2Dir).call();
Gits.resetConfig(git2);
projectFile(project2Dir, 'settings.gradle') << 'rootProject.name = "project2"'
projectFile(project2Dir, '.gitignore') << '.gradle\nbuild\n'
build2File << '''\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;
Expand All @@ -14,9 +15,24 @@
public final class Gits {
private static final SecureRandom random = new SecureRandom();

public static void resetConfig(Git git) {
try {
var config = git.getRepository().getConfig();
config.setString("user", null, "name", "Some Person");
config.setString("user", null, "email", "[email protected]");
config.setString("commit", null, "gpgSign", "false");
config.setString("tag", null, "gpgSign", "false");
config.save();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}

public static Git clone(File dir, Git origin) throws GitAPIException {
var uri = origin.getRepository().getDirectory().getAbsolutePath();
return Git.cloneRepository().setDirectory(dir).setURI(uri).setCloneAllBranches(true).setNoCheckout(false).call();
var git = Git.cloneRepository().setDirectory(dir).setURI(uri).setCloneAllBranches(true).setNoCheckout(false).call();
resetConfig(git);
return git;
}

public static Path repoFile(Git git, String path) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class SettingsCompatTest extends Specification {

def remoteDir = new File(tempDir, 'remote')
remote = Git.init().setDirectory(remoteDir).call()
Gits.resetConfig(remote);

Gits.repoFile(remote, '.gitignore') << '.gradle/\nbuild/\n'
Gits.repoFile(remote, 'master.txt') << 'contents here'
Expand All @@ -34,6 +35,7 @@ class SettingsCompatTest extends Specification {

def remote2Dir = new File(tempDir, 'remote2')
remote2 = Gits.clone(remote2Dir, remote)
Gits.resetConfig(remote2);
}

def 'if no git repo found, version is defaulted'() {
Expand Down

0 comments on commit 4c901a5

Please sign in to comment.