{"thread":{"id":"49201","subject":"[feature] how to output absolute paths in git diff? => --show-abs-path","startedAt":"2018-08-23T09:15:49Z","lastAt":"2018-08-23T11:25:06Z","messageCount":3,"participants":["Timothee Cour","Ævar Arnfjörð Bjarmason"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"356351","messageId":"CANri+EzXBxEf7XtjnJONAYD4h_woqw06-4mcWCH6xODNMMp26w@mail.gmail.com","threadId":"49201","inReplyTo":null,"subject":"[feature] how to output absolute paths in git diff? => --show-abs-path","fromName":"Timothee Cour","fromEmail":"thelastmammoth@gmail.com","sentAt":"2018-08-23T09:15:19Z","receivedAt":"2018-08-23T09:15:49Z","isPatch":false,"sender":{"key":"thelastmammoth@gmail.com","avatar":null},"body":"This has all the context:\nhttps://stackoverflow.com/questions/22698505/how-to-show-full-paths-in-git-diff\n\nI'd like `--show-abs-path` to show absolute paths in:\ngit diff --show-abs-path args...\n\neg:\ngit diff --no-index `get_file1` `get_file2`\ncould show:\n--- a/Users/timothee/temp/ripgrep/help0.txt\n+++ b/help1.txt\n\n* passing '--dst-prefix=$PWD' and '--src-prefix=$PWD' doesn't help\nbecause path arguments could be absolute, so it'll create\n$PWD/Users/timothee/temp/ripgrep/help0.txt (wrong)\n\n* passing '--dst-prefix=.' will behave weirdly, replacing leading `/`\nby `.` (seems wrong)\ndiff --git .Users/timothee/temp/ripgrep/help0.txt b/help1.txt\n\nNOTE: I'm invoking the `git diff` command via a more complicated case\n(with multiple arguments including git diff flags and git diff files),\nso it's awkward for me to parse which arguments correspond to a file\nvs a flag (ie prevents easily converting input file arguments to\nabsolute paths), but `git` could do it easily via a flag, eg\n`--show-abs-path`\n"},{"id":"356352","messageId":"CACBZZX6F1ez-yfnc3asPXBkBd9VKCjS7paN5ZsWVnpn=QUyGew@mail.gmail.com","threadId":"49201","inReplyTo":"CANri+EzXBxEf7XtjnJONAYD4h_woqw06-4mcWCH6xODNMMp26w@mail.gmail.com","subject":"Re: [feature] how to output absolute paths in git diff? => --show-abs-path","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2018-08-23T09:42:40Z","receivedAt":"2018-08-23T09:42:54Z","isPatch":false,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"On Thu, Aug 23, 2018 at 11:16 AM Timothee Cour <thelastmammoth@gmail.com> wrote:\n>\n> This has all the context:\n> https://stackoverflow.com/questions/22698505/how-to-show-full-paths-in-git-diff\n\nIt's helpful to copy it anyway, so we can discuss it here:\n\nQUOTE\n\nHow do I show full paths in git diff? One can use '--dst-prefix=$PWD'\nand '--src-prefix=$PWD' but this is fragile as it won't work in many\ncases, eg with --no-index, or when running the commond from a\nsubdirectory without using --relative=realpath_to_cwd\n\nEND QUOTE\n\nWanting such a feature seems sensible. But I'm unclear on the details.\n\nYou say that --{src,dst}-prefix is fragile and doesn't work for\n--no-index. But if I do this:\n\n    (\n    cd /tmp &&\n    echo foo >a &&\n    echo bar >b &&\n    git --no-pager diff --src-prefix=$PWD/ --dst-prefix=$PWD/ a b\n    )\n\nI get this diff:\n\n    diff --git /tmp/a /tmp/b\n    new file mode 100644\n    index 257cc56..5716ca5 100644\n    --- /tmp/a\n    +++ /tmp/b\n    @@ -1 +1 @@\n    -foo\n    +bar\n\nSo this seems to work for --no-index, or if it doesn't what situations\ndoesn't it work in?\n\n> I'd like `--show-abs-path` to show absolute paths in:\n> git diff --show-abs-path args...\n>\n> eg:\n> git diff --no-index `get_file1` `get_file2`\n> could show:\n> --- a/Users/timothee/temp/ripgrep/help0.txt\n> +++ b/help1.txt\n\nIs this a mistake, or would you only like --show-abs-paths to\nimplicitly supply --src-prefix, but not --dst-prefix? If so, why?\n\n> * passing '--dst-prefix=$PWD' and '--src-prefix=$PWD' doesn't help\n> because path arguments could be absolute, so it'll create\n> $PWD/Users/timothee/temp/ripgrep/help0.txt (wrong)\n\nAh, so it's about supplying both the prefix *and* absolute paths,\nwhereas I see without --no-index we seem to handle this sort of thing\njust fine:\n\n    git diff --src-prefix=$PWD/ --dst-prefix=$PWD HEAD~.. $PWD/some-file\n\n> * passing '--dst-prefix=.' will behave weirdly, replacing leading `/`\n> by `.` (seems wrong)\n> diff --git .Users/timothee/temp/ripgrep/help0.txt b/help1.txt\n\nThis is because the default prefixes are a/ and b/, respectively, and\nthe option allows you to entirely replace them. E.g. imagine needing\n\"../some-relative-path/\"\n\n> NOTE: I'm invoking the `git diff` command via a more complicated case\n> (with multiple arguments including git diff flags and git diff files),\n> so it's awkward for me to parse which arguments correspond to a file\n> vs a flag (ie prevents easily converting input file arguments to\n> absolute paths), but `git` could do it easily via a flag, eg\n> `--show-abs-path`\n"},{"id":"356356","messageId":"CANri+ExMY9G9aSm2TumHd8a9p2ZVXqcBOV-H=7P-_Xh_ng=Cpg@mail.gmail.com","threadId":"49201","inReplyTo":"CACBZZX6F1ez-yfnc3asPXBkBd9VKCjS7paN5ZsWVnpn=QUyGew@mail.gmail.com","subject":"Re: [feature] how to output absolute paths in git diff? => --show-abs-path","fromName":"Timothee Cour","fromEmail":"timothee.cour2@gmail.com","sentAt":"2018-08-23T11:24:37Z","receivedAt":"2018-08-23T11:25:06Z","isPatch":false,"sender":{"key":"timothee.cour2@gmail.com","avatar":null},"body":"> Wanting such a feature seems sensible\n\nhappy to hear that!\n\n> So this seems to work for --no-index, or if it doesn't what situations doesn't it work in?\n\ncases where path arguments are already absolute (as I showed earlier)\n\n\n> Is this a mistake, or would you only like --show-abs-paths to implicitly supply --src-prefix, but not --dst-prefix? If so, why?\n\nnotice I didn't use `--show-abs-paths` in that example; I'm showing\nwhat `git diff` currently outputs (the `could show` meant depending on\nyour use case; eg when `get_file1` returns an absolute path and\n`get_file2` returns a relative one)\n\n> Ah, so it's about supplying both the prefix *and* absolute paths, whereas I see without --no-index we seem to handle this sort of thing just fine:\n\nindeed, without `--no-index` things work just fine as I noted in\nhttps://stackoverflow.com/questions/22698505/how-to-show-full-paths-in-git-diff.\nThe problem is with `--no-index`\nI tried messing around with `--src-prefix` and `--dst-prefix` to\nremedy this but as I showed, it can't work currently.\n\n> without --no-index we seem to handle this sort of thing just fine:\n\nyou also need `--relative` in case you're not at repo root in your\nsnippet (that' what I'm using, without `--no-index`)\n\n\n> This is because the default prefixes are a/ and b/, respectively\n\nthat seems buggy:\nwith default options I get:\n--- a/Users/timothee/help0.txt\n+++ b/help1.txt\n\nwith `--src-prefix=FOO ` and `--dst-prefix=FOO ` I get:\n--- FOOUsers/timothee/help0.txt\n+++ FOOhelp1.txt\n\nthis seems buggy because there's not good option for FOO:\nwhen FOO = /, relative paths become a broken absolute path (/help1.txt)\nwhen FOO = ./, absolute paths become a broken relative path\n(./Users/timothee/help0.txt)\n\nI propose instead to show:\nwith `--src-prefix=FOO ` and `--dst-prefix=FOO ` I get:\n--- join(FOO,path1)\n+++ join(FOO,path2)\n\nwhere join(prefix, path) simply appends prefix to path, taking care of\navoiding a double `//` in case prefix ends in / and path starts with\n/,\n\nthat way, the defauls (with a/, b/) are unchanged and we can have:\nwith `--src-prefix=` and `--dst-prefix=` (empty FOO):\n--- /Users/timothee/help0.txt\n+++ help1.txt\n=> the paths are not broken\n\n## summary:\n\n* `--show-abs-paths` would be useful\n* `--src-prefix=FOO ` and `--dst-prefix=FOO ` could use join(FOO,path)\ninstead of the currently used join(FOO,path1.removeLeadingSlash)\nOn Thu, Aug 23, 2018 at 2:42 AM Ævar Arnfjörð Bjarmason\n<avarab@gmail.com> wrote:\n>\n> On Thu, Aug 23, 2018 at 11:16 AM Timothee Cour <thelastmammoth@gmail.com> wrote:\n> >\n> > This has all the context:\n> > https://stackoverflow.com/questions/22698505/how-to-show-full-paths-in-git-diff\n>\n> It's helpful to copy it anyway, so we can discuss it here:\n>\n> QUOTE\n>\n> How do I show full paths in git diff? One can use '--dst-prefix=$PWD'\n> and '--src-prefix=$PWD' but this is fragile as it won't work in many\n> cases, eg with --no-index, or when running the commond from a\n> subdirectory without using --relative=realpath_to_cwd\n>\n> END QUOTE\n>\n> Wanting such a feature seems sensible. But I'm unclear on the details.\n>\n> You say that --{src,dst}-prefix is fragile and doesn't work for\n> --no-index. But if I do this:\n>\n>     (\n>     cd /tmp &&\n>     echo foo >a &&\n>     echo bar >b &&\n>     git --no-pager diff --src-prefix=$PWD/ --dst-prefix=$PWD/ a b\n>     )\n>\n> I get this diff:\n>\n>     diff --git /tmp/a /tmp/b\n>     new file mode 100644\n>     index 257cc56..5716ca5 100644\n>     --- /tmp/a\n>     +++ /tmp/b\n>     @@ -1 +1 @@\n>     -foo\n>     +bar\n>\n> So this seems to work for --no-index, or if it doesn't what situations\n> doesn't it work in?\n>\n> > I'd like `--show-abs-path` to show absolute paths in:\n> > git diff --show-abs-path args...\n> >\n> > eg:\n> > git diff --no-index `get_file1` `get_file2`\n> > could show:\n> > --- a/Users/timothee/temp/ripgrep/help0.txt\n> > +++ b/help1.txt\n>\n> Is this a mistake, or would you only like --show-abs-paths to\n> implicitly supply --src-prefix, but not --dst-prefix? If so, why?\n>\n> > * passing '--dst-prefix=$PWD' and '--src-prefix=$PWD' doesn't help\n> > because path arguments could be absolute, so it'll create\n> > $PWD/Users/timothee/temp/ripgrep/help0.txt (wrong)\n>\n> Ah, so it's about supplying both the prefix *and* absolute paths,\n> whereas I see without --no-index we seem to handle this sort of thing\n> just fine:\n>\n>     git diff --src-prefix=$PWD/ --dst-prefix=$PWD HEAD~.. $PWD/some-file\n>\n> > * passing '--dst-prefix=.' will behave weirdly, replacing leading `/`\n> > by `.` (seems wrong)\n> > diff --git .Users/timothee/temp/ripgrep/help0.txt b/help1.txt\n>\n> This is because the default prefixes are a/ and b/, respectively, and\n> the option allows you to entirely replace them. E.g. imagine needing\n> \"../some-relative-path/\"\n>\n> > NOTE: I'm invoking the `git diff` command via a more complicated case\n> > (with multiple arguments including git diff flags and git diff files),\n> > so it's awkward for me to parse which arguments correspond to a file\n> > vs a flag (ie prevents easily converting input file arguments to\n> > absolute paths), but `git` could do it easily via a flag, eg\n> > `--show-abs-path`\n"}]}