Re: Testing for existence of a remote branch from a script
- From
Torsten Bögershausen <tboegi@web.de>
- Date
- Jan 6, 2025, 06:51 UTC
- Message-ID
- <20250106065121.GA8844@tb-raspi4>
- In-Reply-To
- <CAFOYHZDQs-mftqLQn5HiFgBWcFN6Z-WDscJt=zVLRyGTo36=HQ@mail.gmail.com>
On Mon, Jan 06, 2025 at 05:40:36PM +1300, Chris Packham wrote:
Show 23 quoted lines
> Hi,
>
> I look after some scripts we use at $dayjob for pushing changes though
> our review system.
>
> For some of our repositories we operate a triangular workflow where
> 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'.
>
> The problem I have is not all our projects use this workflow so I've
> tried to automate the detection of this. My script does something like
>
> br=$(git rev-parse --symbolic-full-name
> refs/remotes/origin/foo_incoming -- 2>/dev/null || echo
> refs/remotes/origin/foo)
>
> The '--' is necessary because if foo_incoming doesn't exist then there
> is extra output on stdout that puts off users. But when foo_incoming
> does exist then br gets set to `refs/remotes/origin/foo_incoming\n--`.
>
> 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