Skip to content

Commit 76cb14e

Browse files
committed
[JENKINS-8342] fix that all commits since the last build are taken into account on calculating the revision candidates. Before only the last commit was used. The list of candidates are used to check against the excludedRegions pattern.
1 parent eeb5dd3 commit 76cb14e

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

src/main/java/hudson/plugins/git/util/DefaultBuildChooser.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,20 @@ public Collection<Revision> getCandidateRevisions(boolean isPollCall, String sin
9191

9292
verbose(listener, "Found a new commit {0} to be built on {1}", sha1, singleBranch);
9393

94-
Revision revision = new Revision(sha1);
95-
revision.getBranches().add(new Branch(singleBranch, sha1));
96-
return Collections.singletonList(revision);
94+
// calculate the revisions that are new compared to the last build
95+
List<ObjectId> allRevs = git.revListAll(); // index 0 contains the newest revision
96+
Revision lastBuiltRev = data.getLastBuiltRevision();
97+
int indexOfLastBuildRev = allRevs.indexOf(lastBuiltRev.getSha1());
98+
List<ObjectId> newRevisionsSinceLastBuild = allRevs.subList(0, indexOfLastBuildRev);
99+
100+
// translate list of ObjectIds into list of Revisions
101+
List<Revision> candidateRevs = new ArrayList<Revision>();
102+
for (ObjectId objectId : newRevisionsSinceLastBuild) {
103+
Revision revision = new Revision(objectId);
104+
revision.getBranches().add(new Branch(singleBranch, sha1));
105+
candidateRevs.add(revision);
106+
}
107+
return candidateRevs;
97108
} catch (GitException e) {
98109
// branch does not exist, there is nothing to build
99110
verbose(listener, "Failed to rev-parse: {0}", singleBranch);

0 commit comments

Comments
 (0)