git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC 3/3] refspec: add support for negative refspecs

From
Jacob Keller <jacob.keller@gmail.com>
Date
Aug 21, 2020, 17:26 UTC
Message-ID
<CA+P7+xq4+RJF5f8v6ZG6mfXKg29Sh4CcFB72tKDPTx5vQLsS1A@mail.gmail.com>
In-Reply-To
<CA+P7+xrPep7caJm2uN+hAqOqZU3b2njpW95JQCzYJdKgbakp8A@mail.gmail.com>
On Fri, Aug 21, 2020 at 10:16 AM Jacob Keller <jacob.keller@gmail.com> wrote:
Show 52 quoted lines
>
> On Tue, Aug 18, 2020 at 10:41 AM Jeff King <peff@peff.net> wrote:
> > Hmm. I think the behavior we'd want is something like:
> >
> >   # make sure the other side has three refs
> >   git branch prune/one HEAD
> >   git branch prune/two HEAD
> >   git branch prune/three HEAD
> >   git push dst.git refs/heads/prune/*
> >
> >   # now drop two of ours, which are eligible for pruning
> >   git branch -d prune/one
> >   git branch -d prune/two
> >
> >   # push with pruning, omitting "two"
> >   git push --prune dst.git refs/heads/prune/* ^refs/heads/prune/two
> >
> >   # we should leave "two" but still deleted "one"
> >   test_write_lines one three >expect
> >   git -C dst.git for-each-ref --format='%(refname:lstrip=3)' refs/heads/prune/ >actual
> >   test_cmp expect actual
> >
> > I.e., the negative refspec shrinks the space we're considering pruning.
> > And we'd probably want a similar test for "fetch --prune".
> >
> > I just tried that, though, and got an interesting result. The push
> > actually complains:
> >
> >   $ git push --prune dst.git refs/heads/prune/* ^refs/heads/prune/two
> >   error: src refspec refs/heads/prune/two does not match any
> >   error: failed to push some refs to 'dst.git'
> >
> > For negative refspecs, would we want to loosen the "must-exist" check?
> > Or really, is this getting into the "are we negative on the src or dst"
> > thing you brought up earlier? Especially with --prune, what I really
> > want to say is "do not touch the remote refs/heads/two".
> >
> > We can get work around it by using a wildcard:
> >
> >   $ git push --prune dst.git refs/heads/prune/* ^refs/heads/prune/two*
> >   To dst.git
> >    - [deleted]         prune/one
> >
> > So it works as I'd expect already with your patch. But I do wonder if
> > there are corner cases around the src/dst thing that might not behave
> > sensibly.
> >
>
> Hmm. So this raises a good point. I added a variation of this test
> where I used separate names for the source and destination. It looks
> like with the current implementation, negative refspecs always apply
> to the destination.

I also tried adding a test for fetch --prune, but that ultimately calls query_refspecs_multiple and query_refspecs. I need to figure out how negative refspecs need to interact with that function still.

Previous: Jacob KellerNext: Jacob Keller
Message 15 of 20 in “[RFC 1/3] refspec: fix documentation referring to refspec_item”
  1. Jacob KellerAug 15, 2020
  2. 2/3 refspec: make sure stack refspec_item variables are zeroedJacob Keller, Aug 15, 2020
  3. Junio C HamanoAug 17, 2020
  4. Jacob KellerAug 17, 2020
  5. 3/3 refspec: add support for negative refspecsJacob Keller, Aug 15, 2020
  6. Jacob KellerAug 17, 2020
  7. Junio C HamanoAug 17, 2020
  8. Jacob KellerAug 18, 2020
  9. Jeff KingAug 18, 2020
  10. Jacob KellerAug 20, 2020
  11. Jeff KingAug 21, 2020
  12. Junio C HamanoAug 21, 2020
  13. Jacob KellerAug 21, 2020
  14. Jacob KellerAug 21, 2020
  15. Jacob KellerAug 21, 2020
  16. Jacob KellerAug 21, 2020
  17. Jeff KingAug 21, 2020
  18. Junio C HamanoAug 17, 2020
  19. Jacob KellerAug 21, 2020
  20. Junio C HamanoAug 21, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.