Enable multi-branch remote polling
For as long as we've been using Jenkins, workspaces have been required for polling on jobs with multiple branches. We have a bunch of jobs where the git repo has a code branch and a packaging branch. The job is set to trigger on changes from either branch, and then build merges them together. Since workspace polling automatically triggers a build if there's no workspace, the build script has to be prepared for the case where it's building the same code and should do nothing.
This works fine except that every time we replace our worker nodes, any event on the remote repository triggers the workspace polling and a build to be run. This is multiplied since we often have multiple sets of stable branches from the repositories that have associated Jenkins jobs. It's a lot of pointless busy work when it should be easy to tell that the two fixed branches configured in each job haven't changed.
This PR enables remote pulling for multiple non-wildcard branches. The code was already there to loop over requested branches, but the mode was only triggered for a single non-wildcard branch. I included two other fixes I came across while running the test suite to ensure I was exercising as I expected.
I found several similar issues but not one that was specifically about remote polling being used for multiple branches. I'm happy to update the PR or commit messages if there is one. Here is a search for all git-plugin issues containing ls-remote.
Testing done
Testing has been done with new unit tests and passing of the existing tests. I haven't had a chance to test this on our instance.
Submitter checklist
- [x] Make sure you are opening from a topic/feature/bugfix branch (right side) and not your main branch!
- [x] Ensure that the pull request title represents the desired changelog entry
- [x] Please describe what you did
- [x] Link to relevant issues in GitHub or Jira
- [ ] Link to relevant pull requests, esp. upstream and downstream changes
- [x] Ensure you have provided tests - that demonstrates feature works or fixes the issue