tg.sh: add fer_branch_contains utility function
commit80b84a68fbf2d2c0be506f93ff0c201ea37cd6d4
authorKyle J. McKay <mackyle@gmail.com>
Tue, 24 Aug 2021 15:13:54 +0000 (24 08:13 -0700)
committerKyle J. McKay <mackyle@gmail.com>
Tue, 24 Aug 2021 15:13:54 +0000 (24 08:13 -0700)
treedb534a19070f8fa261d485c20250e61aec0d429b
parent125c1622ebae95229e90413b88cb0092e401bd67
tg.sh: add fer_branch_contains utility function

Starting with Git version 2.7.0, the `git for-each-ref` command
accepts a `--contains <committish>` option.

Provide a new fer_branch_contains utility function that emulates
`git branch --contains` but using `git for-each-ref` when available
and otherwise falling back to the old `git branch --no-color --contains`
technique that parses and munges the `git branch --contains` output.

The fer_branch_contains function provides the foundation for switching
away from parsing the output of `git branch --contains` since there's
no guarantee that its output will not change in the future whereas
by using `git for-each-ref` with an explicit `--format=%(refname)`
option the output format is guaranteed to remain consistent.

Since the output of `git branch --contains` for versions prior to
Git 2.7.0 will not be changing at this point and that output is
fully parseable, using fer_branch_contains provides future proofing.

Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
tg.sh