Skip to content
Permalink
Browse files

[FIXED JENKINS-9971] Fix NPE when validating remote for publish.

Add new validation to GitPublisher that checks the remote name
is a valid repository name.

Also update validatation in GitSCM to response null repo name
and url parameter values.
  • Loading branch information
kevinsawicki committed Jun 14, 2011
1 parent 6513580 commit 61bd032828366df80589dd2f2aa22f0709c8915a
@@ -28,12 +28,15 @@
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;


import org.apache.commons.lang.StringUtils;

import org.kohsuke.stapler.AncestorInPath;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;

import org.eclipse.jgit.transport.RemoteConfig;

@@ -402,6 +405,31 @@ public FormValidation doCheckTagName(@QueryParameter String value) {
public FormValidation doCheckBranchName(@QueryParameter String value) {
return checkFieldNotEmpty(value, "Branch Name");
}

public FormValidation doCheckRemote(
@AncestorInPath AbstractProject project, StaplerRequest req)
throws IOException, ServletException {
String remote = req.getParameter("value");
boolean isMerge = req.getParameter("isMerge") != null;

// Added isMerge because we don't want to allow empty remote names
// for tag/branch pushes.
if (remote.length() == 0 && isMerge)
return FormValidation.ok();

FormValidation validation = checkFieldNotEmpty(remote,
"Remote Name");
if (validation.kind != FormValidation.Kind.OK)
return validation;

GitSCM scm = (GitSCM) project.getScm();
if (scm.getRepositoryByName(remote) == null)
return FormValidation
.error("No remote repository configured with name '"
+ remote + "'");

return FormValidation.ok();
}

public boolean isApplicable(Class<? extends AbstractProject> jobType) {
return true;
@@ -1528,14 +1528,10 @@ public FormValidation doGitRemoteNameCheck(StaplerRequest req, StaplerResponse r

String[] urls = req.getParameterValues("repo.url");
String[] names = req.getParameterValues("repo.name");

names = GitUtils.fixupNames(names, urls);

for (String name : names) {
if (name.equals(mergeRemoteName)) {
return FormValidation.ok();
}
}
if (urls != null && names != null)
for (String name : GitUtils.fixupNames(names, urls))
if (name.equals(mergeRemoteName))
return FormValidation.ok();

return FormValidation.error("No remote repository configured with name '" + mergeRemoteName + "'");
}
@@ -41,9 +41,7 @@
<f:entry field="targetRepoName"
title="${%Target remote name}">
<f:textbox
checkUrl="'${rootURL}/scm/GitSCM/gitRemoteNameCheck?value='+escape(this.value)
+encodeAllInputs('&amp;', this.form, 'git.repo.name')
+encodeAllInputs('&amp;', this.form, 'git.repo.url')"/>
checkUrl="'descriptorByName/GitPublisher/checkRemote?value='+escape(this.value)"/>
</f:entry>
</table>
<div align="right">
@@ -65,9 +63,7 @@
<f:entry field="targetRepoName"
title="${%Target remote name}">
<f:textbox
checkUrl="'${rootURL}/scm/GitSCM/gitRemoteNameCheck?value='+escape(this.value)
+encodeAllInputs('&amp;', this.form, 'git.repo.name')
+encodeAllInputs('&amp;', this.form, 'git.repo.url')"/>
checkUrl="'descriptorByName/GitPublisher/checkRemote?value='+escape(this.value)" />
</f:entry>
</table>
<div align="right">

0 comments on commit 61bd032

Please sign in to comment.
You can’t perform that action at this time.