Skip to content

Commit

Permalink
[JENKINS-68562] Fix Git checkouts for controllers running on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
dwnusbaum committed May 17, 2022
1 parent 2a53ff4 commit aa42d69
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/main/java/hudson/plugins/git/GitSCM.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
import hudson.Util;
import hudson.plugins.git.extensions.impl.ScmName;
import hudson.util.LogTaskListener;
import java.nio.file.InvalidPathException;
import java.util.Map.Entry;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -1396,14 +1397,29 @@ public void checkout(Run<?, ?> build, Launcher launcher, FilePath workspace, Tas
private void abortIfSourceIsLocal() throws AbortException {
for (UserRemoteConfig userRemoteConfig: getUserRemoteConfigs()) {
String remoteUrl = userRemoteConfig.getUrl();
if (remoteUrl != null && (remoteUrl.toLowerCase(Locale.ENGLISH).startsWith("file://") || Files.exists(Paths.get(remoteUrl)))) {
if (!isRemoteUrlValid(remoteUrl)) {
throw new AbortException("Checkout of Git remote '" + remoteUrl + "' aborted because it references a local directory, " +
"which may be insecure. You can allow local checkouts anyway by setting the system property '" +
ALLOW_LOCAL_CHECKOUT_PROPERTY + "' to true.");
}
}
}

private static boolean isRemoteUrlValid(String remoteUrl) {
if (remoteUrl == null) {
return true;
}
if (remoteUrl.toLowerCase(Locale.ENGLISH).startsWith("file://")) {
return false;
}
try {
// Check for local remotes with no protocol like /path/to/repo.git/
return !Files.exists(Paths.get(remoteUrl));
} catch (InvalidPathException e) {
return true;
}
}

private void printCommitMessageToLog(TaskListener listener, GitClient git, final Build revToBuild)
throws IOException {
try {
Expand Down

0 comments on commit aa42d69

Please sign in to comment.