Skip to content

Commit

Permalink
Merge pull request #475 from jbq/scm_source_compat
Browse files Browse the repository at this point in the history
[JENKINS-42204] GitSCMSource: Fix backwards compatibility for advanced options.
  • Loading branch information
MarkEWaite committed Feb 24, 2017
2 parents d780f27 + fa9190d commit 608a378
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions src/main/java/jenkins/plugins/git/GitSCMSource.java
Expand Up @@ -79,17 +79,22 @@
import java.io.PrintWriter;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.logging.Logger;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

import static org.apache.commons.lang.StringUtils.isBlank;

/**
* @author Stephen Connolly
*/
public class GitSCMSource extends AbstractGitSCMSource {
private static final String DEFAULT_INCLUDES = "*";

private static final String DEFAULT_EXCLUDES = "";

public static final Logger LOGGER = Logger.getLogger(GitSCMSource.class.getName());

private final String remote;
Expand Down Expand Up @@ -119,19 +124,8 @@ public GitSCMSource(String id, String remote, String credentialsId, String remot
super(id);
this.remote = remote;
this.credentialsId = credentialsId;

if (remoteName == null)
// backwards compatibility
this.remoteName = "origin";
else
this.remoteName = remoteName;

if (rawRefSpecs == null)
// backwards compatibility
this.rawRefSpecs = String.format("+refs/heads/*:refs/remotes/%s/*", this.remoteName);
else
this.rawRefSpecs = rawRefSpecs;

this.remoteName = remoteName;
this.rawRefSpecs = rawRefSpecs;
this.includes = includes;
this.excludes = excludes;
this.ignoreOnPushNotifications = ignoreOnPushNotifications;
Expand Down Expand Up @@ -195,6 +189,10 @@ public String getRemote() {

@Override
public String getRemoteName() {
if (isBlank(remoteName))
// backwards compatibility
return super.getRemoteName();

return remoteName;
}

Expand All @@ -215,8 +213,13 @@ public String getExcludes() {
@Override
protected List<RefSpec> getRefSpecs() {
List<RefSpec> refSpecs = new ArrayList<>();
String refSpecsString = rawRefSpecs;

if (isBlank(refSpecsString))
// backwards compatibility
refSpecsString = String.format("+refs/heads/*:refs/remotes/%s/*", getRemoteName());

for (String rawRefSpec : rawRefSpecs.split(" ")) {
for (String rawRefSpec : refSpecsString.split(" ")) {
refSpecs.add(new RefSpec(rawRefSpec));
}

Expand Down

0 comments on commit 608a378

Please sign in to comment.