From: Junio C Hamano <gitster@pobox.com>
To: "Torsten Bögershausen" <tboegi@web.de>
Cc: Chris Packham <judge.packham@gmail.com>, GIT <git@vger.kernel.org>
Subject: Re: Testing for existence of a remote branch from a script
Date: Mon, 06 Jan 2025 07:30:32 -0800 [thread overview]
Message-ID: <xmqqsepw0xk7.fsf@gitster.g> (raw)
In-Reply-To: <20250106065121.GA8844@tb-raspi4> ("Torsten Bögershausen"'s message of "Mon, 6 Jan 2025 07:51:21 +0100")
Torsten Bögershausen <tboegi@web.de> writes:
>> changes are fetched from one branch (e.g. 'foo') but are pushed to a
>> different one ('foo_incoming'). Our CI system runs to test the changes
>> and when they pass 'foo_incoming' is merged (fast-forward most of the
>> time) into 'foo'.
>> ...
>> Is there a better way of checking for the existence of a remote branch?
>
> I may have missed something, would that work:
> git fetch -p
> git branch -r
Or "git ls-remote origin refs/heads/foo-incoming" and see if it
yields anything?
The "workflow" makes me wonder how it would be bootstrapped, though.
When you add a new branch, "bar", to be pre-reviewed before getting
merged at the server side, you want people to push to
"bar-incoming". Before the very initial update to "bar-incoming"
that pushes into "bar-incoming" and creates it, there wouldn't be
"bar-incoming" on the remote side, would there? So "see if
foo-incoming exists and change the behaviour on the client end
accordingly" may not be a strategy to pursue.
If we wanted to support the "workflow" natively, the way we would do
so would be to introduce a protocol capability that allows the
server side to advertise:
If you want to update branch B, you are not allowed to do so
directly. Instead, you are expected to push your changes to
update 'refs/for/B'
and then "git push" on the client end would notice the capability
and turns "git push origin B" (or, more likely, the user is on local
branch B that is to build on the remote branch B from 'origin', and
"git push" with no arguments would do the right thing) into such an
update.
I am not suggesting that we jump to the above immediately. But the
reason why I am bringing it up is because The "how would I see if
they have foo-incoming?" smells like seeking a way to implement such
a custom capability advertisement outside Git.
A few random thoughts.
- Would it be useful if we introduced the ability to advertise
"custom capabilities" from the receiving end of the connection,
that does not affect how the rest of Git behaves at all? It
would be sort of the reverse of --server-option, which is a
mechanism to let the client to tell the other side out of band
information that the rest of Git is oblivious.
The other side of course needs a way to inspect what capabilities
are advertised. For "--server-option", I do not think our server
end does anything special, but other implementations can act on
them. This new thing can start the same way.
- If this is a poor-man's custom capability advertisement, perhaps
the server end can create a ref "refs/capabilities/incoming"
(whose value does not really matter) and your client side can see
if there is such a ref with "ls-remote"? That may be a more
robust thing to do instead, perhaps, as you do not need to worry
about "What about a new branch 'bar'?" bootstrapping issues.
next prev parent reply other threads:[~2025-01-06 15:30 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-06 4:40 Testing for existence of a remote branch from a script Chris Packham
2025-01-06 6:51 ` Torsten Bögershausen
2025-01-06 15:30 ` Junio C Hamano [this message]
2025-01-06 16:36 ` Theodore Ts'o
2025-01-06 18:44 ` Junio C Hamano
2025-01-06 20:50 ` Chris Packham
2025-01-06 15:05 ` Theodore Ts'o
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqqsepw0xk7.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=judge.packham@gmail.com \
--cc=tboegi@web.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).