Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rudikershaw/git-build-hook
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3.3.0
Choose a base ref
...
head repository: rudikershaw/git-build-hook
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3.4.0
Choose a head ref
  • 11 commits
  • 14 files changed
  • 2 contributors

Commits on Aug 23, 2022

  1. Verified

    This commit was signed with the committer’s verified signature.
    rudikershaw Rudi Kershaw
    Copy the full SHA
    56e06d4 View commit details

Commits on Feb 17, 2023

  1. Verified

    This commit was signed with the committer’s verified signature.
    rudikershaw Rudi Kershaw
    Copy the full SHA
    ca5e74a View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    rudikershaw Rudi Kershaw
    Copy the full SHA
    135a6f7 View commit details
  3. Verified

    This commit was signed with the committer’s verified signature.
    rudikershaw Rudi Kershaw
    Copy the full SHA
    6d57507 View commit details
  4. Verified

    This commit was signed with the committer’s verified signature.
    rudikershaw Rudi Kershaw
    Copy the full SHA
    9e58c3f View commit details

Commits on Feb 18, 2023

  1. Trigger Travis CI test.

    rudikershaw committed Feb 18, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    rudikershaw Rudi Kershaw
    Copy the full SHA
    aefbd72 View commit details

Commits on Mar 1, 2023

  1. Remove readonly

    etzelc authored and rudikershaw committed Mar 1, 2023
    Copy the full SHA
    ae0b2e9 View commit details

Commits on Mar 3, 2023

  1. Verified

    This commit was signed with the committer’s verified signature.
    rudikershaw Rudi Kershaw
    Copy the full SHA
    58a1d2f View commit details

Commits on Mar 4, 2023

  1. Verified

    This commit was signed with the committer’s verified signature.
    rudikershaw Rudi Kershaw
    Copy the full SHA
    7c2457c View commit details
  2. Finalise 3.4.0

    rudikershaw committed Mar 4, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    rudikershaw Rudi Kershaw
    Copy the full SHA
    6a5370a View commit details
  3. Re-finalize 3.4.0

    rudikershaw committed Mar 4, 2023

    Verified

    This commit was signed with the committer’s verified signature.
    rudikershaw Rudi Kershaw
    Copy the full SHA
    d3b14e4 View commit details
2 changes: 1 addition & 1 deletion .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -14,5 +14,5 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.0/apache-maven-3.9.0-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ A common use-case might be to install local git hooks by setting the `core.hooks
<plugin>
<groupId>com.rudikershaw.gitbuildhook</groupId>
<artifactId>git-build-hook-maven-plugin</artifactId>
<version>3.2.0</version>
<version>3.3.0</version>
<configuration>
<gitConfig>
<!-- The location of the directory you are using to store the Git hooks in your project. -->
58 changes: 24 additions & 34 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@

<groupId>com.rudikershaw.gitbuildhook</groupId>
<artifactId>git-build-hook-maven-plugin</artifactId>
<version>3.3.0</version>
<version>3.4.0</version>
<packaging>maven-plugin</packaging>

<name>Git Build Hook Maven Plugin</name>
@@ -31,7 +31,7 @@
<scm>
<connection>scm:git:git://github.com/rudikershaw/git-build-hook.git</connection>
<developerConnection>scm:git:ssh://github.com:rudikershaw/git-build-hook.git</developerConnection>
<url>http://github.com/rudikershaw/git-build-hook/tree/master</url>
<url>http://github.com/rudikershaw/git-build-hook/tree/main</url>
</scm>

<prerequisites>
@@ -43,7 +43,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<maven.version>3.8.6</maven.version>
<maven.version>3.9.0</maven.version>
</properties>

<dependencies>
@@ -115,37 +115,8 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.2.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.12.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
</plugin>
<!-- Override jar and install plugin for extra pre-test install to a custom repo for testing. -->
<!-- Problem: The integration tests run using Maven verifier API are testing projects run from the previous build. -->
<!-- Solution: Override jar and install plugin for extra pre-test install to a custom repo for testing. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
@@ -208,6 +179,25 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.rudikershaw</groupId>
<artifactId>remove-attached-artifact-maven-plugin</artifactId>
<version>1.1.0</version>
<executions>
<execution>
<id>remove-attached-artifacts</id>
<goals>
<goal>remove</goal>
</goals>
<configuration>
<artifactIds>
<artifactId>${project.groupId}:${project.artifactId}:jar:TEST:${project.version}</artifactId>
<artifactId>${project.groupId}:${project.artifactId}:test-jar:CPHOOKS:${project.version}</artifactId>
</artifactIds>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
10 changes: 9 additions & 1 deletion src/main/java/com/rudikershaw/gitbuildhook/GitConfigMojo.java
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ public class GitConfigMojo extends GitRepositoryValidator {
private MavenProject project;

/** The git config to set and the values to set them to. */
@Parameter(readonly = true)
@Parameter
private Map<String, String> gitConfig;

@Override
@@ -34,6 +34,14 @@ public void execute() throws MojoFailureException {
final FileRepositoryBuilder repoBuilder = new FileRepositoryBuilder();
repoBuilder.findGitDir(project.getBasedir());

if (repoBuilder.getGitDir().getAbsolutePath().contains(".git/worktrees/")) {
getLog().warn(
"The plugin appears to be running in a Git worktree. "
+ "Worktree configuration is not currently supported. No configuration changes made."
);
return;
}

try (Git git = Git.open(repoBuilder.getGitDir())) {
final StoredConfig config = git.getRepository().getConfig();
for (final Map.Entry<String, String> entry : gitConfig.entrySet()) {
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@
public class InstallMojo extends GitRepositoryValidator {

/** The location of git hooks to install into the default hooks directory. */
@Parameter(readonly = true)
@Parameter
private final Map<String, String> installHooks = new HashMap<>();

/** Injected MavenProject containing project related information such as base directory. */
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.rudikershaw.gitbuildhook.validation;

import java.io.IOException;

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;

/** Abstract class containing the logic required to fail a goal if there is no valid git repository. */
@@ -21,13 +18,7 @@ protected void validateGitRepository(final MavenProject project) throws MojoFail
final FileRepositoryBuilder repoBuilder = new FileRepositoryBuilder();
repoBuilder.findGitDir(project.getBasedir());

if (repoBuilder.getGitDir() != null) {
try (Git git = Git.open(repoBuilder.getGitDir())) {
getLog().info("Found the local git repository.");
} catch (final IOException e) {
failBuildBecauseRepoCouldNotBeFound(e);
}
} else {
if (repoBuilder.getGitDir() == null) {
failBuildBecauseRepoCouldNotBeFound(null);
}
}
27 changes: 21 additions & 6 deletions src/test/java/com/rudikershaw/gitbuildhook/AbstractMojoTest.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package com.rudikershaw.gitbuildhook;

import static org.junit.Assert.assertTrue;
import org.apache.commons.io.FileUtils;
import org.apache.maven.it.VerificationException;
import org.apache.maven.it.Verifier;
import org.apache.maven.plugin.testing.MojoRule;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;

import org.apache.maven.it.VerificationException;
import org.apache.maven.plugin.testing.MojoRule;
import org.junit.Rule;
import org.junit.rules.TemporaryFolder;
import org.apache.maven.it.Verifier;
import static org.junit.Assert.assertTrue;

/** Abstract test for Mojos. */
public class AbstractMojoTest {
@@ -41,6 +44,18 @@ public TemporaryFolder getFolder() {
return folder;
}

@Before
public void setup() throws IOException {
FileUtils.copyDirectory(new File("./.mvn"), new File(folder.getRoot().getAbsolutePath() + "/.mvn"));
Files.copy(Paths.get("mvnw"), Paths.get(folder.getRoot().getAbsolutePath() + "/mvnw"));
Files.copy(Paths.get("mvnw.cmd"), Paths.get(folder.getRoot().getAbsolutePath() + "/mvnw.cmd"));
}

@After
public void teardown() throws IOException {
FileUtils.deleteDirectory(folder.getRoot());
}

/**
* Move a file for a specified test folder into a temporary directory for testing.
*
4 changes: 2 additions & 2 deletions src/test/resources/default-test-project/pom.xml
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>

<groupId>com.rudikershaw.gitbuildhook</groupId>
<artifactId>git-build-hook</artifactId>
<artifactId>test-artifact</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Test MyMojo</name>
@@ -15,7 +15,7 @@
<plugin>
<groupId>com.rudikershaw.gitbuildhook</groupId>
<artifactId>git-build-hook-maven-plugin</artifactId>
<version>3.3.0</version>
<version>3.4.0</version>
</plugin>
</plugins>
</build>
4 changes: 2 additions & 2 deletions src/test/resources/test-project-configure/pom.xml
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>

<groupId>com.rudikershaw.gitbuildhook</groupId>
<artifactId>git-build-hook</artifactId>
<artifactId>test-artifact</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Test MyMojo</name>
@@ -15,7 +15,7 @@
<plugin>
<groupId>com.rudikershaw.gitbuildhook</groupId>
<artifactId>git-build-hook-maven-plugin</artifactId>
<version>3.3.0</version>
<version>3.4.0</version>
<configuration>
<gitConfig>
<core.hooksPath>hooks-path/</core.hooksPath>
4 changes: 2 additions & 2 deletions src/test/resources/test-project-initialise/pom.xml
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>

<groupId>com.rudikershaw.gitbuildhook</groupId>
<artifactId>git-build-hook</artifactId>
<artifactId>test-artifact</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Test MyMojo</name>
@@ -15,7 +15,7 @@
<plugin>
<groupId>com.rudikershaw.gitbuildhook</groupId>
<artifactId>git-build-hook-maven-plugin</artifactId>
<version>3.3.0</version>
<version>3.4.0</version>
<executions>
<execution>
<goals>
4 changes: 2 additions & 2 deletions src/test/resources/test-project-install-hooks/pom.xml
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>

<groupId>com.rudikershaw.gitbuildhook</groupId>
<artifactId>git-build-hook</artifactId>
<artifactId>test-artifact</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Test MyMojo</name>
@@ -15,7 +15,7 @@
<plugin>
<groupId>com.rudikershaw.gitbuildhook</groupId>
<artifactId>git-build-hook-maven-plugin</artifactId>
<version>3.3.0</version>
<version>3.4.0</version>
<configuration>
<installHooks>
<pre-commit>hook-to-install.sh</pre-commit>
4 changes: 2 additions & 2 deletions src/test/resources/test-project-invalid-hook/pom.xml
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>

<groupId>com.rudikershaw.gitbuildhook</groupId>
<artifactId>git-build-hook</artifactId>
<artifactId>test-artifact</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Test MyMojo</name>
@@ -15,7 +15,7 @@
<plugin>
<groupId>com.rudikershaw.gitbuildhook</groupId>
<artifactId>git-build-hook-maven-plugin</artifactId>
<version>3.3.0</version>
<version>3.4.0</version>
<configuration>
<installHooks>
<pre-commit-oops>hook-to-install.sh</pre-commit-oops>
4 changes: 2 additions & 2 deletions src/test/resources/test-project-reinstall-hooks/pom.xml
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>

<groupId>com.rudikershaw.gitbuildhook</groupId>
<artifactId>git-build-hook</artifactId>
<artifactId>test-artifact</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Test MyMojo</name>
@@ -15,7 +15,7 @@
<plugin>
<groupId>com.rudikershaw.gitbuildhook</groupId>
<artifactId>git-build-hook-maven-plugin</artifactId>
<version>3.3.0</version>
<version>3.4.0</version>
<configuration>
<installHooks>
<pre-commit>hook-to-install.sh</pre-commit>
4 changes: 2 additions & 2 deletions src/test/resources/test-project-reinstall-hooks/pom2.xml
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>

<groupId>com.rudikershaw.gitbuildhook</groupId>
<artifactId>git-build-hook</artifactId>
<artifactId>test-artifact</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Test MyMojo</name>
@@ -15,7 +15,7 @@
<plugin>
<groupId>com.rudikershaw.gitbuildhook</groupId>
<artifactId>git-build-hook-maven-plugin</artifactId>
<version>3.3.0</version>
<version>3.4.0</version>
<configuration>
<installHooks>
<pre-commit>hook-to-reinstall.sh</pre-commit>