From: Phillip Wood <phillip.wood123@gmail.com>
To: Ondra Medek <xmedeko@gmail.com>, phillip.wood@dunelm.org.uk
Cc: git@vger.kernel.org
Subject: Re: Feature request: git status --branch-only
Date: Tue, 14 Nov 2023 15:02:04 +0000 [thread overview]
Message-ID: <00033c86-dbd7-4c88-bfbd-8f6766cd66c9@gmail.com> (raw)
In-Reply-To: <CAJsoDaHX3t9bViq0F7gmJPD+PoE-ZqmJS5h=u-W900x9KEMmYA@mail.gmail.com>
Hi Ondra
On 14/11/2023 12:40, Ondra Medek wrote:
> Hi Phillip,
>
> it does not work for a fresh clone of an empty repository
>
> git for-each-ref --format="%(upstream:short)" refs/heads/master
>
> outputs nothing, while
Oh dear, that's a shame. I wonder if it is a bug because the
documentation says that
--format="%(upstream:track)"
should print "[gone]" whenever an unknown upstream ref is encountered
but trying that on a clone of an empty repository gives no output.
Best Wishes
Phillip
> git status -b --no-ahead-behind --porcelain=v2
>
> outputs
>
> # branch.oid (initial)
> # branch.head master
> # branch.upstream origin/master
>
> I.e. it outputs a proper upstream branch.
>
> Best regards
> Ondra
>
> Ondra Medek
>
>
> On Tue, 14 Nov 2023 at 13:28, Phillip Wood <phillip.wood123@gmail.com> wrote:
>>
>> Hi Ondra
>>
>> On 14/11/2023 10:16, Ondra Medek wrote:
>>> Hello,
>>> I am working on a tol which should fetch changes from a remote
>>> repository on a user click. I want to limit fetch on the current
>>> remote tracking branch (something like "origin/master"), but
>>> surprisingly, it's hard to get it for all corner cases like a fresh
>>> clone of an empty repository or detached head, etc. E.g see this SO
>>> thread https://stackoverflow.com/questions/171550/find-out-which-remote-branch-a-local-branch-is-tracking/52896538
>>
>> I think you can do this by calling
>>
>> git symbolic-ref --quiet HEAD
>>
>> to get the full refname of the current branch. If HEAD is detached it
>> will print nothing and exit with exit code 1. Then you can call
>>
>> git for-each-ref --format="%(upstream:short)" $refname
>>
>> to get the upstream branch
>>
>> Best Wishes
>>
>> Phillip
>
next prev parent reply other threads:[~2023-11-14 15:02 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-14 10:16 Feature request: git status --branch-only Ondra Medek
2023-11-14 12:28 ` Phillip Wood
2023-11-14 12:40 ` Ondra Medek
2023-11-14 15:02 ` Phillip Wood [this message]
2023-11-14 19:44 ` Ondra Medek
2023-11-14 20:18 ` Jeff King
2023-11-16 16:09 ` phillip.wood123
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=00033c86-dbd7-4c88-bfbd-8f6766cd66c9@gmail.com \
--to=phillip.wood123@gmail.com \
--cc=git@vger.kernel.org \
--cc=phillip.wood@dunelm.org.uk \
--cc=xmedeko@gmail.com \
/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).