Skip to content

Commit c320ffe

Browse files
committed
Attempt a fix for #1806 by preventing JGit from finding the native git executable.
1 parent 6c1df6d commit c320ffe

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (
1818
* Support configuration of mirrors for P2 repositories in maven DSL ([#1697](https://github.com/diffplug/spotless/issues/1697)).
1919
### Fixed
2020
* Fix support for plugins when using Prettier version `3.0.0` and newer. ([#1802](https://github.com/diffplug/spotless/pull/1802))
21+
* Fix configuration cache issue around `external process started '/usr/bin/git --version'`. ([#1806](https://github.com/diffplug/spotless/issues/1806))
2122
### Changes
2223
* Bump default `flexmark` version to latest `0.64.0` -> `0.64.8`. ([#1801](https://github.com/diffplug/spotless/pull/1801))
2324
* Bump default `ktlint` version to latest `0.50.0` -> `1.0.0`. ([#1808](https://github.com/diffplug/spotless/pull/1808))

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/GitRatchetGradle.java

+72-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020-2021 DiffPlug
2+
* Copyright 2020-2023 DiffPlug
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,10 +19,33 @@
1919

2020
import javax.annotation.Nullable;
2121

22+
import org.eclipse.jgit.lib.Config;
23+
import org.eclipse.jgit.storage.file.FileBasedConfig;
24+
import org.eclipse.jgit.util.FS;
25+
import org.eclipse.jgit.util.SystemReader;
26+
2227
import com.diffplug.spotless.extra.GitRatchet;
2328

2429
/** Gradle implementation of GitRatchet. */
2530
public class GitRatchetGradle extends GitRatchet<File> {
31+
static {
32+
preventJGitFromCallingExecutables();
33+
}
34+
35+
static void preventJGitFromCallingExecutables() {
36+
SystemReader reader = SystemReader.getInstance();
37+
SystemReader.setInstance(new DelegatingSystemReader(reader) {
38+
@Override
39+
public String getenv(String variable) {
40+
if ("PATH".equals(variable)) {
41+
return "";
42+
} else {
43+
return super.getenv(variable);
44+
}
45+
}
46+
});
47+
}
48+
2649
@Override
2750
protected File getDir(File project) {
2851
return project;
@@ -32,4 +55,52 @@ protected File getDir(File project) {
3255
protected @Nullable File getParent(File project) {
3356
return project.getParentFile();
3457
}
58+
59+
static class DelegatingSystemReader extends SystemReader {
60+
final SystemReader reader;
61+
62+
DelegatingSystemReader(SystemReader reader) {
63+
this.reader = reader;
64+
}
65+
66+
@Override
67+
public String getHostname() {
68+
return reader.getHostname();
69+
}
70+
71+
@Override
72+
public String getenv(String variable) {
73+
return reader.getProperty(variable);
74+
}
75+
76+
@Override
77+
public String getProperty(String key) {
78+
return reader.getProperty(key);
79+
}
80+
81+
@Override
82+
public FileBasedConfig openUserConfig(Config parent, FS fs) {
83+
return reader.openUserConfig(parent, fs);
84+
}
85+
86+
@Override
87+
public FileBasedConfig openSystemConfig(Config parent, FS fs) {
88+
return reader.openSystemConfig(parent, fs);
89+
}
90+
91+
@Override
92+
public FileBasedConfig openJGitConfig(Config parent, FS fs) {
93+
return reader.openJGitConfig(parent, fs);
94+
}
95+
96+
@Override
97+
public long getCurrentTime() {
98+
return reader.getCurrentTime();
99+
}
100+
101+
@Override
102+
public int getTimezone(long when) {
103+
return reader.getTimezone(when);
104+
}
105+
}
35106
}

0 commit comments

Comments
 (0)