Fix branch matching logic

Based on Jim's feedback, change the branch matching logic to always
have priority over ref matching. And v3 will always have refs, so no
need to check if that attribute exists. Also adds a test that checks the
current breakage of branch matching logic.

Change-Id: Iba148b73a77b3300ad84db1c05c083d2c82cd950
5 files changed