I don't see any way how to get the closest branch to the git tag name other than to:
1) Do the checkout on the default buildNode found by getBuildNode (hence for master).
2) Perform git magic to find closest branch name
You need to do git magic because git doesn’t know what “branch” a tag is from
Branches are just named pointers.
The name *you* pick on your local clone need not be the same as the name I pick for mine.
Hence your ‘master’ might be my ‘junk’
So what you want to do is use a specific repo as the “canonical” repo and find the nearest named mutable pointer in that repo
That will require pulling all refs from the canonical, not pulling just the tag (slower builds, but you have non-standard requirements, and that is the cost you pay) and then you can ask git for the branch name in the canonical repo that is closest to the tag (and happens before)