# Should `git remote show` display excluded branches as to-be-fetched?

6 messages from 2022-06-10 to 2022-06-25. Participants: Pavel Rappo, Junio C Hamano, Jacob Keller.
Thread: https://gitlist.dev/t/57981

## Pavel Rappo, 2022-06-10 12:59

Subject: Should `git remote show` display excluded branches as to-be-fetched?
Message-ID: <CAChcVumTgNqRTt=EtThXiw9ga=W9WC-uS0XOkz7T+TbtGKeU+w@mail.gmail.com>
URL: https://gitlist.dev/e/CAChcVumTgNqRTt%3DEtThXiw9ga%3DW9WC-uS0XOkz7T%2BTbtGKeU%2Bw%40mail.gmail.com

```
Here's a console session:

  % git config --get-all remote.jdk19.fetch
  +refs/heads/*:refs/remotes/jdk19/*
  ^refs/heads/pr/*

  % git remote show jdk19

  * remote jdk19
    Fetch URL: git@github.com:openjdk/jdk19.git
    Push  URL: git@github.com:openjdk/jdk19.git
    HEAD branch: master
    Remote branches:
      master tracked
      pr/1   new (next fetch will store in remotes/jdk19)
      pr/2   new (next fetch will store in remotes/jdk19)
      pr/3   new (next fetch will store in remotes/jdk19)
    Local ref configured for 'git push':
      master pushes to master (fast-forwardable)

I would naively expect the pr/1, pr/2, and pr/3 branches to be either:

- not displayed, or better
- displayed with a hint that they won't be fetched (since they match a
_negative_ refspec, which is the second line in the `git config`
output above)

Thanks,
-Pavel

```

## Junio C Hamano, 2022-06-10 17:08

Subject: Re: Should `git remote show` display excluded branches as to-be-fetched?
Message-ID: <xmqq1qvwfntm.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqq1qvwfntm.fsf%40gitster.g
In-Reply-To: <CAChcVumTgNqRTt=EtThXiw9ga=W9WC-uS0XOkz7T+TbtGKeU+w@mail.gmail.com>

```
Pavel Rappo <pavel.rappo@gmail.com> writes:

> Here's a console session:
>
>   % git config --get-all remote.jdk19.fetch
>   +refs/heads/*:refs/remotes/jdk19/*
>   ^refs/heads/pr/*

Thanks

"Negative refspecs" is relatively new feature introduced in c0192df6
(refspec: add support for negative refspecs, 2020-09-30), so it
would not be so surprising if it still had some surprising behaviour
;-)

Jacob, care to take a look?

>   % git remote show jdk19
>
>   * remote jdk19
>     Fetch URL: git@github.com:openjdk/jdk19.git
>     Push  URL: git@github.com:openjdk/jdk19.git
>     HEAD branch: master
>     Remote branches:
>       master tracked
>       pr/1   new (next fetch will store in remotes/jdk19)
>       pr/2   new (next fetch will store in remotes/jdk19)
>       pr/3   new (next fetch will store in remotes/jdk19)
>     Local ref configured for 'git push':
>       master pushes to master (fast-forwardable)
>
> I would naively expect the pr/1, pr/2, and pr/3 branches to be either:
>
> - not displayed, or better
> - displayed with a hint that they won't be fetched (since they match a
> _negative_ refspec, which is the second line in the `git config`
> output above)
>
> Thanks,
> -Pavel

```

## Jacob Keller, 2022-06-12 06:36

Subject: Re: Should `git remote show` display excluded branches as to-be-fetched?
Message-ID: <CA+P7+xqfthRZkn76FxG8xuGU670k0zyCCTe0d26_pe1HVTkXpQ@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2BP7%2BxqfthRZkn76FxG8xuGU670k0zyCCTe0d26_pe1HVTkXpQ%40mail.gmail.com
In-Reply-To: <xmqq1qvwfntm.fsf@gitster.g>

```
On Fri, Jun 10, 2022 at 10:08 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> Pavel Rappo <pavel.rappo@gmail.com> writes:
>
> > Here's a console session:
> >
> >   % git config --get-all remote.jdk19.fetch
> >   +refs/heads/*:refs/remotes/jdk19/*
> >   ^refs/heads/pr/*
>
> Thanks
>
> "Negative refspecs" is relatively new feature introduced in c0192df6
> (refspec: add support for negative refspecs, 2020-09-30), so it
> would not be so surprising if it still had some surprising behaviour
> ;-)
>
> Jacob, care to take a look?
>
> >   % git remote show jdk19
> >
> >   * remote jdk19
> >     Fetch URL: git@github.com:openjdk/jdk19.git
> >     Push  URL: git@github.com:openjdk/jdk19.git
> >     HEAD branch: master
> >     Remote branches:
> >       master tracked
> >       pr/1   new (next fetch will store in remotes/jdk19)
> >       pr/2   new (next fetch will store in remotes/jdk19)
> >       pr/3   new (next fetch will store in remotes/jdk19)
> >     Local ref configured for 'git push':
> >       master pushes to master (fast-forwardable)
> >
> > I would naively expect the pr/1, pr/2, and pr/3 branches to be either:
> >
> > - not displayed, or better
> > - displayed with a hint that they won't be fetched (since they match a
> > _negative_ refspec, which is the second line in the `git config`
> > output above)
> >
> > Thanks,
> > -Pavel

This is almost certainly an oversight in that the particular code path
does not process negative refspecs. I can hopefully take a closer look
at this next week.

```

## Jacob Keller, 2022-06-13 23:20

Subject: Re: Should `git remote show` display excluded branches as to-be-fetched?
Message-ID: <CA+P7+xrfkApv_r_YQqOt-LiaC=Ctb2px0UuaSwqU_ua_qmH4OA@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2BP7%2BxrfkApv_r_YQqOt-LiaC%3DCtb2px0UuaSwqU_ua_qmH4OA%40mail.gmail.com
In-Reply-To: <xmqq1qvwfntm.fsf@gitster.g>

```
On Fri, Jun 10, 2022 at 10:08 AM Junio C Hamano <gitster@pobox.com> wrote:
>
> Pavel Rappo <pavel.rappo@gmail.com> writes:
>
> > Here's a console session:
> >
> >   % git config --get-all remote.jdk19.fetch
> >   +refs/heads/*:refs/remotes/jdk19/*
> >   ^refs/heads/pr/*
>
> Thanks
>
> "Negative refspecs" is relatively new feature introduced in c0192df6
> (refspec: add support for negative refspecs, 2020-09-30), so it
> would not be so surprising if it still had some surprising behaviour
> ;-)
>
> Jacob, care to take a look?
>

Ok, so this looks like its caused by the fact that get_fetch_map in
builtin/remote.c ignores all negative refspecs. I think what we really
want to do is check if a given ref matches any negative ref and then
maybe move it from the new listing into a separate skipped listing.

Figuring out the best way to do this is a little bit of a challenge.
It looks like maybe we need to use one of the functions in remote.c
just after the get_fetch_map call in get_ref_states. But exactly what
has so far eluded me after a bit of digging.

I'm still looking at this, but help would be appreciated if anyone
else has a suggestion.

Thanks,
Jake

> >   % git remote show jdk19
> >
> >   * remote jdk19
> >     Fetch URL: git@github.com:openjdk/jdk19.git
> >     Push  URL: git@github.com:openjdk/jdk19.git
> >     HEAD branch: master
> >     Remote branches:
> >       master tracked
> >       pr/1   new (next fetch will store in remotes/jdk19)
> >       pr/2   new (next fetch will store in remotes/jdk19)
> >       pr/3   new (next fetch will store in remotes/jdk19)
> >     Local ref configured for 'git push':
> >       master pushes to master (fast-forwardable)
> >
> > I would naively expect the pr/1, pr/2, and pr/3 branches to be either:
> >
> > - not displayed, or better
> > - displayed with a hint that they won't be fetched (since they match a
> > _negative_ refspec, which is the second line in the `git config`
> > output above)
> >
> > Thanks,
> > -Pavel

```

## Jacob Keller, 2022-06-14 00:34

Subject: Re: Should `git remote show` display excluded branches as to-be-fetched?
Message-ID: <CA+P7+xrwapFU6z9P7HOKmcGUVFiAn20PVahGG=SC=KSDTv0hNw@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2BP7%2BxrwapFU6z9P7HOKmcGUVFiAn20PVahGG%3DSC%3DKSDTv0hNw%40mail.gmail.com
In-Reply-To: <CA+P7+xrfkApv_r_YQqOt-LiaC=Ctb2px0UuaSwqU_ua_qmH4OA@mail.gmail.com>

```
On Mon, Jun 13, 2022 at 4:20 PM Jacob Keller <jacob.keller@gmail.com> wrote:
>
> On Fri, Jun 10, 2022 at 10:08 AM Junio C Hamano <gitster@pobox.com> wrote:
> >
> > Pavel Rappo <pavel.rappo@gmail.com> writes:
> >
> > > Here's a console session:
> > >
> > >   % git config --get-all remote.jdk19.fetch
> > >   +refs/heads/*:refs/remotes/jdk19/*
> > >   ^refs/heads/pr/*
> >
> > Thanks
> >
> > "Negative refspecs" is relatively new feature introduced in c0192df6
> > (refspec: add support for negative refspecs, 2020-09-30), so it
> > would not be so surprising if it still had some surprising behaviour
> > ;-)
> >
> > Jacob, care to take a look?
> >
>
> Ok, so this looks like its caused by the fact that get_fetch_map in
> builtin/remote.c ignores all negative refspecs. I think what we really
> want to do is check if a given ref matches any negative ref and then
> maybe move it from the new listing into a separate skipped listing.
>
> Figuring out the best way to do this is a little bit of a challenge.
> It looks like maybe we need to use one of the functions in remote.c
> just after the get_fetch_map call in get_ref_states. But exactly what
> has so far eluded me after a bit of digging.
>
> I'm still looking at this, but help would be appreciated if anyone
> else has a suggestion.
>
> Thanks,
> Jake
>
> > >   % git remote show jdk19
> > >
> > >   * remote jdk19
> > >     Fetch URL: git@github.com:openjdk/jdk19.git
> > >     Push  URL: git@github.com:openjdk/jdk19.git
> > >     HEAD branch: master
> > >     Remote branches:
> > >       master tracked
> > >       pr/1   new (next fetch will store in remotes/jdk19)
> > >       pr/2   new (next fetch will store in remotes/jdk19)
> > >       pr/3   new (next fetch will store in remotes/jdk19)
> > >     Local ref configured for 'git push':
> > >       master pushes to master (fast-forwardable)
> > >
> > > I would naively expect the pr/1, pr/2, and pr/3 branches to be either:
> > >
> > > - not displayed, or better
> > > - displayed with a hint that they won't be fetched (since they match a
> > > _negative_ refspec, which is the second line in the `git config`
> > > output above)
> > >
> > > Thanks,
> > > -Pavel

I found a working solution, but I don't really like the
implementation, so perhaps someone with more knowledge of the struct
refspec, struct refspec_item, etc would help me figure out if I am
doing it in a good way. I just posted it.

Thanks,
Jake

```

## Pavel Rappo, 2022-06-25 16:06

Subject: Re: Should `git remote show` display excluded branches as to-be-fetched?
Message-ID: <CAChcVu=HRECdUCjgNywiG=o+S8DvAtqYd7TjzrvFiZZq80Xaog@mail.gmail.com>
URL: https://gitlist.dev/e/CAChcVu%3DHRECdUCjgNywiG%3Do%2BS8DvAtqYd7TjzrvFiZZq80Xaog%40mail.gmail.com
In-Reply-To: <CA+P7+xrwapFU6z9P7HOKmcGUVFiAn20PVahGG=SC=KSDTv0hNw@mail.gmail.com>

```
On Tue, Jun 14, 2022 at 1:34 AM Jacob Keller <jacob.keller@gmail.com> wrote:

> I found a working solution, but I don't really like the
> implementation, so perhaps someone with more knowledge of the struct
> refspec, struct refspec_item, etc would help me figure out if I am
> doing it in a good way. I just posted it.

Thanks, Jake. Does Git project have an issue tracker we could enter
this bug into?

```
