Permalink
Browse files

Allow remotePolling on single (qualified) branch with multiple

repositories
[FIXED JENKINS-25414]
  • Loading branch information...
wannessels committed Nov 3, 2014
1 parent 54cd07e commit c82b8e888a5810189e7c641e846468954d41ad4c
Showing with 37 additions and 3 deletions.
  1. +17 −3 src/main/java/hudson/plugins/git/GitSCM.java
  2. +20 −0 src/test/java/hudson/plugins/git/GitSCMTest.java
@@ -453,12 +453,26 @@ public static String getParameterString(String original, EnvVars env) {
*/
private String getSingleBranch(EnvVars env) {
// if we have multiple branches skip to advanced usecase
if (getBranches().size() != 1 || getRepositories().size() != 1) {
if (getBranches().size() != 1) {
return null;
}

String branch = getBranches().get(0).getName();
String repository = getRepositories().get(0).getName();
String repository = null;

if (getRepositories().size() != 1) {
for (RemoteConfig repo : getRepositories()) {
if (branch.startsWith(repo.getName() + "/")) {
repository = repo.getName();
break;
}
}
if (repository == null) {
return null;
}
} else {
repository = getRepositories().get(0).getName();
}


// replace repository wildcard with repository name
if (branch.startsWith("*/")) {
@@ -1417,6 +1417,26 @@ private boolean gitVersionAtLeast(int neededMajor, int neededMinor) throws IOExc
final int gitMinor = Integer.parseInt(fields[1]);
return gitMajor >= neededMajor && gitMinor >= neededMinor;
}

public void testPolling_CanDoRemotePollingIfOneBranchButMultipleRepositories() throws Exception {
FreeStyleProject project = createFreeStyleProject();
List<UserRemoteConfig> remoteConfigs = new ArrayList<UserRemoteConfig>();
remoteConfigs.add(new UserRemoteConfig(testRepo.gitDir.getAbsolutePath(), "origin", "", null));
remoteConfigs.add(new UserRemoteConfig(testRepo.gitDir.getAbsolutePath(), "someOtherRepo", "", null));
GitSCM scm = new GitSCM(remoteConfigs,
Collections.singletonList(new BranchSpec("origin/master")), false,
Collections.<SubmoduleConfig> emptyList(), null, null,
Collections.<GitSCMExtension> emptyList());
project.setScm(scm);
commit("commitFile1", johnDoe, "Commit number 1");

FreeStyleBuild first_build = project.scheduleBuild2(0, new Cause.UserCause()).get();
assertBuildStatus(Result.SUCCESS, first_build);

first_build.getWorkspace().deleteContents();
PollingResult pollingResult = scm.poll(project, null, first_build.getWorkspace(), listener, null);
assertFalse(pollingResult.hasChanges());
}

/**
* Test for JENKINS-24467.

0 comments on commit c82b8e8

Please sign in to comment.