Skip to content

Commit aa42d69

Browse files
committed
[JENKINS-68562] Fix Git checkouts for controllers running on Windows
1 parent 2a53ff4 commit aa42d69

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/main/java/hudson/plugins/git/GitSCM.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
import hudson.Util;
105105
import hudson.plugins.git.extensions.impl.ScmName;
106106
import hudson.util.LogTaskListener;
107+
import java.nio.file.InvalidPathException;
107108
import java.util.Map.Entry;
108109
import java.util.regex.Matcher;
109110
import java.util.regex.Pattern;
@@ -1396,14 +1397,29 @@ public void checkout(Run<?, ?> build, Launcher launcher, FilePath workspace, Tas
13961397
private void abortIfSourceIsLocal() throws AbortException {
13971398
for (UserRemoteConfig userRemoteConfig: getUserRemoteConfigs()) {
13981399
String remoteUrl = userRemoteConfig.getUrl();
1399-
if (remoteUrl != null && (remoteUrl.toLowerCase(Locale.ENGLISH).startsWith("file://") || Files.exists(Paths.get(remoteUrl)))) {
1400+
if (!isRemoteUrlValid(remoteUrl)) {
14001401
throw new AbortException("Checkout of Git remote '" + remoteUrl + "' aborted because it references a local directory, " +
14011402
"which may be insecure. You can allow local checkouts anyway by setting the system property '" +
14021403
ALLOW_LOCAL_CHECKOUT_PROPERTY + "' to true.");
14031404
}
14041405
}
14051406
}
14061407

1408+
private static boolean isRemoteUrlValid(String remoteUrl) {
1409+
if (remoteUrl == null) {
1410+
return true;
1411+
}
1412+
if (remoteUrl.toLowerCase(Locale.ENGLISH).startsWith("file://")) {
1413+
return false;
1414+
}
1415+
try {
1416+
// Check for local remotes with no protocol like /path/to/repo.git/
1417+
return !Files.exists(Paths.get(remoteUrl));
1418+
} catch (InvalidPathException e) {
1419+
return true;
1420+
}
1421+
}
1422+
14071423
private void printCommitMessageToLog(TaskListener listener, GitClient git, final Build revToBuild)
14081424
throws IOException {
14091425
try {

0 commit comments

Comments
 (0)