Re: [PATCH] for-each-ref: add %(upstream:gone) to mark missing refs
- From
Jeff King <peff@peff.net>
- Date
- Aug 24, 2016, 18:05 UTC
- Message-ID
- <20160824180541.jrliwgkrqu2siywd@sigill.intra.peff.net>
- In-Reply-To
- <20160819215023.10770-1-oystwa@gmail.com>
On Fri, Aug 19, 2016 at 11:50:23PM +0200, Øystein Walle wrote:
Show 7 quoted lines
> git branch -vv will show "gone" next to a remote tracking branch if it > does not exist. for-each-ref is suitable for parsing but had no way of > showing this information. > > This introduces "%(upstream:gone)" to display "gone" in the formatted > output if the ref does not exist or an empty string otherwise, analogous > to git branch -vv.
Hmm. So this sounds like the minimum thing to implement "branch -vv" output, but it feels sort of weirdly non-orthogonal. I guess you'd say:
%(upstream:track)%(upstream:gone)
and assume that only one of them will show any data.
I almost wonder if %(upstream:track) should just output some specific token for the "gone" case, which matches what "branch -vv" does.
(I'm also not sure we can match "branch -vv" exactly here anyway, as it looks like "[%(upstream): %(upstream:track)"], but our "%(upstream:track)" uses its own brackets.)
I suppose that is a backwards-incompatible change for "%(upstream:track)", but I'm not sure how much we have promised about its format. The error cases seem totally undocumented.
Show 5 quoted lines
> --- > Documentation/git-for-each-ref.txt | 5 +++-- > ref-filter.c | 10 +++++++++- > t/t6300-for-each-ref.sh | 12 ++++++++++++ > 3 files changed, 24 insertions(+), 3 deletions(-)
The code itself looks OK to me (assuming we want upstream:gone as the interface), with a few minor nits in the test:
> +test_expect_success 'Check that :gone produces expected results' ' > + cat >expected <<-\EOF && > +gone > + EOF
The "<<-" will strip leading tabs, meaning you can indent "gone" here to match the rest of the test.
> + test_when_finished "git config branch.master.merge refs/heads/master" && > + git config branch.master.merge refs/heads/does-not-exist &&
I thought this could be test_config, but it is not clever enough to restore an old value, only to remove a value we just added. So this is probably the best solution.
Show 5 quoted lines
> + git for-each-ref \ > + --format="%(upstream:gone)" \ > + refs/heads >actual && > + test_cmp expected actual > +'
This tests only that we show "gone"; do you want to add a second branch and make sure that it shows nothing? Maybe you could even use a new branch name, which makes test_config applicable again:
cat >expected <<-\EOF && master no-upstream gone EOF git branch refs/heads/no-upstream && test_config branch.no-upstream.remote . && test_config branch.no-upstream.merge refs/heads/does-not-exist && git for-each-ref --format="%(refname:short) %(upstream:gone)" >actual && test_cmp expected actual
-Peff