{"thread":{"id":"62453","subject":"[Question] How to force relative path output when using `git status --porcelain=2 -z`","startedAt":"2024-11-05T16:59:56Z","lastAt":"2024-11-06T05:07:58Z","messageCount":3,"participants":["叶志晟","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"506668","messageId":"CAH1CY-=FtMTSisCmcz7ovciPomXYBogjNCmqO1mEjN9H6zEfgQ@mail.gmail.com","threadId":"62453","inReplyTo":null,"subject":"[Question] How to force relative path output when using `git status --porcelain=2 -z`","fromName":"叶志晟","fromEmail":"yzs981130@gmail.com","sentAt":"2024-11-05T16:59:43Z","receivedAt":"2024-11-05T16:59:56Z","isPatch":false,"sender":{"key":"yzs981130@gmail.com","avatar":null},"body":"Hi all,\n\nI am experiencing a problem when parsing the results of `git status`.\nMy primary goal is to parse the output of `git status`\nprogrammatically, so I am trying to parse the result of `git status\n--porcelain=2 -z`.\n\nAccording to the docs [here](https://git-scm.com/docs/git-status), the\n`-z` option only changes the entry terminations and implies the\n`--porcelain=v1` output format if no other format is given. However,\nthe result shows that the path returned is a relative path to the repo\nroot rather than the current directory when using `-z`. Simply using\n`git status --porcelain=2` returns the relative path to the current\ndirectory.\n\nI am wondering how to force the path to be relative to the current\ndirectory (for easier cutting and pasting) rather than the repo root\nwhen using `git status --porcelain=2 -z`. I would really appreciate it\nif you could help me!\n\nRegards,\nZhisheng\n"},{"id":"506689","messageId":"xmqqses5qis5.fsf@gitster.g","threadId":"62453","inReplyTo":"CAH1CY-=FtMTSisCmcz7ovciPomXYBogjNCmqO1mEjN9H6zEfgQ@mail.gmail.com","subject":"Re: [Question] How to force relative path output when using `git status --porcelain=2 -z`","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-11-06T00:59:22Z","receivedAt":"2024-11-06T00:59:25Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"叶志晟 <yzs981130@gmail.com> writes:\n\n> I am experiencing a problem when parsing the results of `git status`.\n> My primary goal is to parse the output of `git status`\n> programmatically, so I am trying to parse the result of `git status\n> --porcelain=2 -z`.\n\nInteresting finding.  Here is what I tried in my working tree, where\nI have a few cruft files left at the top, and ran these commands\ninside the 't/' subdirectory:\n\n    $ git status --porcelain=1\n    ?? +ps8-v2-reftable-iterator-reuse\n    ?? :runme.sh\n    : git t/master; git status --porcelain=2\n    ? ../+ps8-v2-reftable-iterator-reuse\n    ? ../:runme.sh\n    : git t/master; git status --porcelain=1 -z | tr '\\0' '\\n'\n    ?? +ps8-v2-reftable-iterator-reuse\n    ?? :runme.sh\n    : git t/master; git status --porcelain=2 -z | tr '\\0' '\\n'\n    ? +ps8-v2-reftable-iterator-reuse\n    ? :runme.sh\n\nI haven't dug into the history to see if these inconsistencies in\nbehaviour are deliberate, but I somehow suspect that the output from\n\"--porcelain=2\" without \"-z\" is mistaken.  As the porcelain output\nis designed to be machine parseable with or without \"-z\" (and the\nreader of the output, the implementation of a Porcelain command, is\nresponsible for turning it into relative if it prefers), it would be\na mistake to turn relative output on based on the lack of \"-z\".\n\nNot that we can \"fix\" the output from \"--porcelain=2\" at this point.\nTo changge them to uniformly show absolute (or relative for that\nmatter), we'd need \"--porcelain=3\" to preserve these inconsistency\noutput because it is very certain that existing users and scripts\nalready rely on it.\n\nThanks.\n"},{"id":"506699","messageId":"CAH1CY-kD1MhuuVW8UqkJeiFZkgv2zDBXb1u6q3DLNbUs4R6zXg@mail.gmail.com","threadId":"62453","inReplyTo":"xmqqses5qis5.fsf@gitster.g","subject":"Re: [Question] How to force relative path output when using `git status --porcelain=2 -z`","fromName":"叶志晟","fromEmail":"yzs981130@gmail.com","sentAt":"2024-11-06T05:07:45Z","receivedAt":"2024-11-06T05:07:58Z","isPatch":false,"sender":{"key":"yzs981130@gmail.com","avatar":null},"body":"Hi Junio,\n\nThank you for the quick response! That is exactly what I have encountered.\n\nI understand that it is highly probable that the result of `git status\n--porcelain=2` is unexpected, and it may not be fixed due to\nconsistency.\n\nThanks a lot!\n\n\nJunio C Hamano <gitster@pobox.com> 于2024年11月6日周三 08:59写道：\n>\n> 叶志晟 <yzs981130@gmail.com> writes:\n>\n> > I am experiencing a problem when parsing the results of `git status`.\n> > My primary goal is to parse the output of `git status`\n> > programmatically, so I am trying to parse the result of `git status\n> > --porcelain=2 -z`.\n>\n> Interesting finding.  Here is what I tried in my working tree, where\n> I have a few cruft files left at the top, and ran these commands\n> inside the 't/' subdirectory:\n>\n>     $ git status --porcelain=1\n>     ?? +ps8-v2-reftable-iterator-reuse\n>     ?? :runme.sh\n>     : git t/master; git status --porcelain=2\n>     ? ../+ps8-v2-reftable-iterator-reuse\n>     ? ../:runme.sh\n>     : git t/master; git status --porcelain=1 -z | tr '\\0' '\\n'\n>     ?? +ps8-v2-reftable-iterator-reuse\n>     ?? :runme.sh\n>     : git t/master; git status --porcelain=2 -z | tr '\\0' '\\n'\n>     ? +ps8-v2-reftable-iterator-reuse\n>     ? :runme.sh\n>\n> I haven't dug into the history to see if these inconsistencies in\n> behaviour are deliberate, but I somehow suspect that the output from\n> \"--porcelain=2\" without \"-z\" is mistaken.  As the porcelain output\n> is designed to be machine parseable with or without \"-z\" (and the\n> reader of the output, the implementation of a Porcelain command, is\n> responsible for turning it into relative if it prefers), it would be\n> a mistake to turn relative output on based on the lack of \"-z\".\n>\n> Not that we can \"fix\" the output from \"--porcelain=2\" at this point.\n> To changge them to uniformly show absolute (or relative for that\n> matter), we'd need \"--porcelain=3\" to preserve these inconsistency\n> output because it is very certain that existing users and scripts\n> already rely on it.\n>\n> Thanks.\n\n\n\n-- \n\n\n志晟 叶\nyezhisheng.com.cn\n"}]}