Add multi-branch support for project-templates

Currently, to avoid confusion, we simply ignore project-template
definitions after the first.  However, a more intuitive approach
would be, if the template appears on multiple branches, to have
it reflect those branches.

To that end, add implied branch matchers to templates in the same
way that we do to jobs themselves.  This should provide the same
intuitive behavior where a template defined in zuul-jobs will apply
to all branches, but one defined in a multi-branch repository will
add jobs with implied branch matchers.

When a template is defined more than once, combine them (in the same
way that multiple project definitions are defined) so the resulting
template contains all the jobs (likely with implied branch matchers).

Allow a template to be defined multiple times (e.g., branches) within
the same project, but do not allow it to be redefined in another
project.

Because the multiple project definitions in different branches may
end up applying the same template (which will have all of the
per-branch jobs) multiple times, detect duplicate job definitions
when applying templates and filter them out.

The test test_dynamic_template was originally written to verify that
a project could not redefine a template defined in another project.
Clarify that, and update it to support the newly reported error in
that condition.

Change-Id: I6613885a8c7ebf400e85041e0d68b2eb5ceb033f
9 files changed