Permalink
Browse files

Merge pull request #331 from ndeloof/JENKINS-29066

[JENKINS-29066] potential fix
  • Loading branch information...
MarkEWaite committed Jul 6, 2015
2 parents e051c32 + 06dc97f commit 3745d562fcad08cda294eaf9bc56e9c8840463f3
Showing with 61 additions and 3 deletions.
  1. +21 −3 src/main/java/hudson/plugins/git/GitSCM.java
  2. +40 −0 src/test/java/hudson/plugins/git/GitSCMTest.java
@@ -518,7 +518,7 @@ private boolean requiresWorkspaceForPolling(EnvVars environment) {
for (GitSCMExtension ext : getExtensions()) {
if (ext.requiresWorkspaceForPolling()) return true;
}
return false;
return getSingleBranch(environment) == null;
}

@Override
@@ -566,6 +566,8 @@ private PollingResult compareRemoteRevisionWithImpl(Job<?, ?> project, Launcher

final EnvVars pollEnv = project instanceof AbstractProject ? GitUtils.getPollEnvironment((AbstractProject) project, workspace, launcher, listener, false) : lastBuild.getEnvironment(listener);

final String singleBranch = getSingleBranch(pollEnv);

if (!requiresWorkspaceForPolling(pollEnv)) {

final EnvVars environment = project instanceof AbstractProject ? GitUtils.getPollEnvironment((AbstractProject) project, workspace, launcher, listener, false) : new EnvVars();
@@ -574,6 +576,8 @@ private PollingResult compareRemoteRevisionWithImpl(Job<?, ?> project, Launcher

for (RemoteConfig remoteConfig : getParamExpandedRepos(lastBuild, listener)) {
String remote = remoteConfig.getName();
List<RefSpec> refSpecs = getRefSpecs(remoteConfig, environment);

for (URIish urIish : remoteConfig.getURIs()) {
String gitRepo = urIish.toString();
Map<String, ObjectId> heads = git.getHeadRev(gitRepo);
@@ -582,10 +586,25 @@ private PollingResult compareRemoteRevisionWithImpl(Job<?, ?> project, Launcher
return BUILD_NOW;
}

listener.getLogger().println("Found "+ heads.size() +" remote heads on " + urIish);

Iterator<Entry<String, ObjectId>> it = heads.entrySet().iterator();
while (it.hasNext()) {
String head = it.next().getKey();
for (RefSpec spec : refSpecs) {
if (!spec.matchSource(head)) {
listener.getLogger().println("Ignoring " + head + " as it doesn't match configured refspecs");
it.remove();
break;
}
}
}


for (BranchSpec branchSpec : getBranches()) {
for (Entry<String, ObjectId> entry : heads.entrySet()) {
final String head = entry.getKey();
// head is "refs/(heads|tags)/branchName
// head is "refs/(heads|tags|whatever)/branchName

// first, check the a canonical git reference is configured
if (!branchSpec.matches(head, environment)) {
@@ -637,7 +656,6 @@ private PollingResult compareRemoteRevisionWithImpl(Job<?, ?> project, Launcher

listener.getLogger().println("Polling for changes in");

final String singleBranch = getSingleBranch(pollEnv);
Collection<Revision> candidates = getBuildChooser().getCandidateRevisions(
true, singleBranch, git, listener, buildData, new BuildChooserContextImpl(project, null, environment));

@@ -1428,6 +1428,46 @@ public void testPolling_environmentValueInBranchSpec() throws Exception {
assertFalse("No changes to git since last build, thus no new build is expected", project.poll(listener).hasChanges());
}

@Issue("JENKINS-29066")
public void baseTestPolling_parentHead(List<GitSCMExtension> extensions) throws Exception {
// create parameterized project with environment value in branch specification
FreeStyleProject project = createFreeStyleProject();
GitSCM scm = new GitSCM(
createRemoteRepositories(),
Collections.singletonList(new BranchSpec("**")),
false, Collections.<SubmoduleConfig>emptyList(),
null, null,
extensions);
project.setScm(scm);

// commit something in order to create an initial base version in git
commit("toto/commitFile1", johnDoe, "Commit number 1");
git.branch("someBranch");
commit("toto/commitFile2", johnDoe, "Commit number 2");

assertTrue("polling should detect changes",project.poll(listener).hasChanges());

// build the project
build(project, Result.SUCCESS);

/* Expects 1 build because the build of someBranch incorporates all
* the changes from the master branch as well as the changes from someBranch.
*/
assertEquals("Wrong number of builds", 1, project.getBuilds().size());

assertFalse("polling should not detect changes",project.poll(listener).hasChanges());
}

@Issue("JENKINS-29066")
public void testPolling_parentHead() throws Exception {
baseTestPolling_parentHead(Collections.<GitSCMExtension>emptyList());
}

@Issue("JENKINS-29066")
public void testPolling_parentHead_DisableRemotePoll() throws Exception {
baseTestPolling_parentHead(Collections.<GitSCMExtension>singletonList(new DisableRemotePoll()));
}

public void testPollingAfterManualBuildWithParametrizedBranchSpec() throws Exception {
// create parameterized project with environment value in branch specification
FreeStyleProject project = createFreeStyleProject();

0 comments on commit 3745d56

Please sign in to comment.