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.4.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.1
Choose a head ref
  • 5 commits
  • 14 files changed
  • 1 contributor

Commits on Mar 4, 2023

  1. Verified

    This commit was signed with the committer’s verified signature.
    sxzz Kevin Deng
    Copy the full SHA
    8038b50 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    sxzz Kevin Deng
    Copy the full SHA
    e9222ab View commit details
  3. Verified

    This commit was signed with the committer’s verified signature.
    sxzz Kevin Deng
    Copy the full SHA
    8c89f2a View commit details

Commits on Mar 5, 2023

  1. Switch develop to 3.4.1-SNAPSHOT and add thread safety features to co…

    …nfig an initialise goals.
    rudikershaw committed Mar 5, 2023

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    a30bd84 View commit details
  2. Finalise 3.4.1

    rudikershaw committed Mar 5, 2023

    Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    e8471cd View commit details
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.3.0</version>
<version>3.4.1</version>
<configuration>
<gitConfig>
<!-- The location of the directory you are using to store the Git hooks in your project. -->
2 changes: 1 addition & 1 deletion 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.4.0</version>
<version>3.4.1</version>
<packaging>maven-plugin</packaging>

<name>Git Build Hook Maven Plugin</name>
23 changes: 13 additions & 10 deletions src/main/java/com/rudikershaw/gitbuildhook/GitConfigMojo.java
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
import java.io.IOException;
import java.util.Map;

import com.rudikershaw.gitbuildhook.threadsafety.ClassLock;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
@@ -37,21 +38,23 @@ public void execute() throws MojoFailureException {
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."
+ "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()) {
final String[] conf = stringToConfigArray(entry.getKey());
config.setString(conf[0], conf[1], conf[2], entry.getValue());
getLog().info("Git config '" + entry.getKey() + "' set to - " + entry.getValue());
synchronized (ClassLock.class) {
try (Git git = Git.open(repoBuilder.getGitDir())) {
final StoredConfig config = git.getRepository().getConfig();
for (final Map.Entry<String, String> entry : gitConfig.entrySet()) {
final String[] conf = stringToConfigArray(entry.getKey());
config.setString(conf[0], conf[1], conf[2], entry.getValue());
getLog().info("Git config '" + entry.getKey() + "' set to - " + entry.getValue());
}
config.save();
} catch (final IOException ioe) {
failBuildBecauseRepoCouldNotBeFound(ioe);
}
config.save();
} catch (final IOException ioe) {
failBuildBecauseRepoCouldNotBeFound(ioe);
}
}

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.rudikershaw.gitbuildhook;

import com.rudikershaw.gitbuildhook.threadsafety.ClassLock;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
@@ -44,7 +45,9 @@ private boolean isGitRepoInitialised() {
*/
private void initialiseGitRepository() throws MojoFailureException {
try {
Git.init().setDirectory(project.getBasedir()).call();
synchronized (ClassLock.class) {
Git.init().setDirectory(project.getBasedir()).call();
}
} catch (final GitAPIException e) {
if (!isGitRepoInitialised()) {
throw new MojoFailureException("Could not initialise a local git repository.", e);
Original file line number Diff line number Diff line change
@@ -72,7 +72,7 @@ private void installGitHook(final String hookName, final String filePath, final
}

/**
* Copies the specified file from the file system into the the default hooks directory.
* Copies the specified file from the file system into the default hooks directory.
*
* @param filePath path to the file to use as the hook.
* @param gitHookPathStr the location to move the file to.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.rudikershaw.gitbuildhook.threadsafety;

/**
* Class to act as a universal lock for non-thread safe operations of the plugin.
*/
public class ClassLock {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/** Package containing classes for aiding in the thread safety of the plugin. */
package com.rudikershaw.gitbuildhook.threadsafety;
2 changes: 1 addition & 1 deletion src/test/resources/default-test-project/pom.xml
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
<plugin>
<groupId>com.rudikershaw.gitbuildhook</groupId>
<artifactId>git-build-hook-maven-plugin</artifactId>
<version>3.4.0</version>
<version>3.4.1</version>
</plugin>
</plugins>
</build>
2 changes: 1 addition & 1 deletion src/test/resources/test-project-configure/pom.xml
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
<plugin>
<groupId>com.rudikershaw.gitbuildhook</groupId>
<artifactId>git-build-hook-maven-plugin</artifactId>
<version>3.4.0</version>
<version>3.4.1</version>
<configuration>
<gitConfig>
<core.hooksPath>hooks-path/</core.hooksPath>
2 changes: 1 addition & 1 deletion src/test/resources/test-project-initialise/pom.xml
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
<plugin>
<groupId>com.rudikershaw.gitbuildhook</groupId>
<artifactId>git-build-hook-maven-plugin</artifactId>
<version>3.4.0</version>
<version>3.4.1</version>
<executions>
<execution>
<goals>
2 changes: 1 addition & 1 deletion src/test/resources/test-project-install-hooks/pom.xml
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
<plugin>
<groupId>com.rudikershaw.gitbuildhook</groupId>
<artifactId>git-build-hook-maven-plugin</artifactId>
<version>3.4.0</version>
<version>3.4.1</version>
<configuration>
<installHooks>
<pre-commit>hook-to-install.sh</pre-commit>
2 changes: 1 addition & 1 deletion src/test/resources/test-project-invalid-hook/pom.xml
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
<plugin>
<groupId>com.rudikershaw.gitbuildhook</groupId>
<artifactId>git-build-hook-maven-plugin</artifactId>
<version>3.4.0</version>
<version>3.4.1</version>
<configuration>
<installHooks>
<pre-commit-oops>hook-to-install.sh</pre-commit-oops>
2 changes: 1 addition & 1 deletion src/test/resources/test-project-reinstall-hooks/pom.xml
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
<plugin>
<groupId>com.rudikershaw.gitbuildhook</groupId>
<artifactId>git-build-hook-maven-plugin</artifactId>
<version>3.4.0</version>
<version>3.4.1</version>
<configuration>
<installHooks>
<pre-commit>hook-to-install.sh</pre-commit>
2 changes: 1 addition & 1 deletion src/test/resources/test-project-reinstall-hooks/pom2.xml
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@
<plugin>
<groupId>com.rudikershaw.gitbuildhook</groupId>
<artifactId>git-build-hook-maven-plugin</artifactId>
<version>3.4.0</version>
<version>3.4.1</version>
<configuration>
<installHooks>
<pre-commit>hook-to-reinstall.sh</pre-commit>