public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
* [Question] How to force relative path output when using `git status --porcelain=2 -z`
@ 2024-11-05 16:59 叶志晟
  2024-11-06  0:59 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: 叶志晟 @ 2024-11-05 16:59 UTC (permalink / raw)
  To: git

Hi all,

I am experiencing a problem when parsing the results of `git status`.
My primary goal is to parse the output of `git status`
programmatically, so I am trying to parse the result of `git status
--porcelain=2 -z`.

According to the docs [here](https://git-scm.com/docs/git-status), the
`-z` option only changes the entry terminations and implies the
`--porcelain=v1` output format if no other format is given. However,
the result shows that the path returned is a relative path to the repo
root rather than the current directory when using `-z`. Simply using
`git status --porcelain=2` returns the relative path to the current
directory.

I am wondering how to force the path to be relative to the current
directory (for easier cutting and pasting) rather than the repo root
when using `git status --porcelain=2 -z`. I would really appreciate it
if you could help me!

Regards,
Zhisheng

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Question] How to force relative path output when using `git status --porcelain=2 -z`
  2024-11-05 16:59 [Question] How to force relative path output when using `git status --porcelain=2 -z` 叶志晟
@ 2024-11-06  0:59 ` Junio C Hamano
  2024-11-06  5:07   ` 叶志晟
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2024-11-06  0:59 UTC (permalink / raw)
  To: 叶志晟; +Cc: git

叶志晟 <yzs981130@gmail•com> writes:

> I am experiencing a problem when parsing the results of `git status`.
> My primary goal is to parse the output of `git status`
> programmatically, so I am trying to parse the result of `git status
> --porcelain=2 -z`.

Interesting finding.  Here is what I tried in my working tree, where
I have a few cruft files left at the top, and ran these commands
inside the 't/' subdirectory:

    $ git status --porcelain=1
    ?? +ps8-v2-reftable-iterator-reuse
    ?? :runme.sh
    : git t/master; git status --porcelain=2
    ? ../+ps8-v2-reftable-iterator-reuse
    ? ../:runme.sh
    : git t/master; git status --porcelain=1 -z | tr '\0' '\n'
    ?? +ps8-v2-reftable-iterator-reuse
    ?? :runme.sh
    : git t/master; git status --porcelain=2 -z | tr '\0' '\n'
    ? +ps8-v2-reftable-iterator-reuse
    ? :runme.sh

I haven't dug into the history to see if these inconsistencies in
behaviour are deliberate, but I somehow suspect that the output from
"--porcelain=2" without "-z" is mistaken.  As the porcelain output
is designed to be machine parseable with or without "-z" (and the
reader of the output, the implementation of a Porcelain command, is
responsible for turning it into relative if it prefers), it would be
a mistake to turn relative output on based on the lack of "-z".

Not that we can "fix" the output from "--porcelain=2" at this point.
To changge them to uniformly show absolute (or relative for that
matter), we'd need "--porcelain=3" to preserve these inconsistency
output because it is very certain that existing users and scripts
already rely on it.

Thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Question] How to force relative path output when using `git status --porcelain=2 -z`
  2024-11-06  0:59 ` Junio C Hamano
@ 2024-11-06  5:07   ` 叶志晟
  0 siblings, 0 replies; 3+ messages in thread
From: 叶志晟 @ 2024-11-06  5:07 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Hi Junio,

Thank you for the quick response! That is exactly what I have encountered.

I understand that it is highly probable that the result of `git status
--porcelain=2` is unexpected, and it may not be fixed due to
consistency.

Thanks a lot!


Junio C Hamano <gitster@pobox•com> 于2024年11月6日周三 08:59写道:
>
> 叶志晟 <yzs981130@gmail•com> writes:
>
> > I am experiencing a problem when parsing the results of `git status`.
> > My primary goal is to parse the output of `git status`
> > programmatically, so I am trying to parse the result of `git status
> > --porcelain=2 -z`.
>
> Interesting finding.  Here is what I tried in my working tree, where
> I have a few cruft files left at the top, and ran these commands
> inside the 't/' subdirectory:
>
>     $ git status --porcelain=1
>     ?? +ps8-v2-reftable-iterator-reuse
>     ?? :runme.sh
>     : git t/master; git status --porcelain=2
>     ? ../+ps8-v2-reftable-iterator-reuse
>     ? ../:runme.sh
>     : git t/master; git status --porcelain=1 -z | tr '\0' '\n'
>     ?? +ps8-v2-reftable-iterator-reuse
>     ?? :runme.sh
>     : git t/master; git status --porcelain=2 -z | tr '\0' '\n'
>     ? +ps8-v2-reftable-iterator-reuse
>     ? :runme.sh
>
> I haven't dug into the history to see if these inconsistencies in
> behaviour are deliberate, but I somehow suspect that the output from
> "--porcelain=2" without "-z" is mistaken.  As the porcelain output
> is designed to be machine parseable with or without "-z" (and the
> reader of the output, the implementation of a Porcelain command, is
> responsible for turning it into relative if it prefers), it would be
> a mistake to turn relative output on based on the lack of "-z".
>
> Not that we can "fix" the output from "--porcelain=2" at this point.
> To changge them to uniformly show absolute (or relative for that
> matter), we'd need "--porcelain=3" to preserve these inconsistency
> output because it is very certain that existing users and scripts
> already rely on it.
>
> Thanks.



-- 


志晟 叶
yezhisheng.com.cn

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-11-06  5:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-05 16:59 [Question] How to force relative path output when using `git status --porcelain=2 -z` 叶志晟
2024-11-06  0:59 ` Junio C Hamano
2024-11-06  5:07   ` 叶志晟

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox