git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: timothee.cour2@gmail.com
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: [feature] how to output absolute paths in git diff? => --show-abs-path
Date: Thu, 23 Aug 2018 11:42:40 +0200	[thread overview]
Message-ID: <CACBZZX6F1ez-yfnc3asPXBkBd9VKCjS7paN5ZsWVnpn=QUyGew@mail.gmail.com> (raw)
In-Reply-To: <CANri+EzXBxEf7XtjnJONAYD4h_woqw06-4mcWCH6xODNMMp26w@mail.gmail.com>

On Thu, Aug 23, 2018 at 11:16 AM Timothee Cour <thelastmammoth@gmail.com> wrote:
>
> This has all the context:
> https://stackoverflow.com/questions/22698505/how-to-show-full-paths-in-git-diff

It's helpful to copy it anyway, so we can discuss it here:

QUOTE

How do I show full paths in git diff? One can use '--dst-prefix=$PWD'
and '--src-prefix=$PWD' but this is fragile as it won't work in many
cases, eg with --no-index, or when running the commond from a
subdirectory without using --relative=realpath_to_cwd

END QUOTE

Wanting such a feature seems sensible. But I'm unclear on the details.

You say that --{src,dst}-prefix is fragile and doesn't work for
--no-index. But if I do this:

    (
    cd /tmp &&
    echo foo >a &&
    echo bar >b &&
    git --no-pager diff --src-prefix=$PWD/ --dst-prefix=$PWD/ a b
    )

I get this diff:

    diff --git /tmp/a /tmp/b
    new file mode 100644
    index 257cc56..5716ca5 100644
    --- /tmp/a
    +++ /tmp/b
    @@ -1 +1 @@
    -foo
    +bar

So this seems to work for --no-index, or if it doesn't what situations
doesn't it work in?

> I'd like `--show-abs-path` to show absolute paths in:
> git diff --show-abs-path args...
>
> eg:
> git diff --no-index `get_file1` `get_file2`
> could show:
> --- a/Users/timothee/temp/ripgrep/help0.txt
> +++ b/help1.txt

Is this a mistake, or would you only like --show-abs-paths to
implicitly supply --src-prefix, but not --dst-prefix? If so, why?

> * passing '--dst-prefix=$PWD' and '--src-prefix=$PWD' doesn't help
> because path arguments could be absolute, so it'll create
> $PWD/Users/timothee/temp/ripgrep/help0.txt (wrong)

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:

    git diff --src-prefix=$PWD/ --dst-prefix=$PWD HEAD~.. $PWD/some-file

> * passing '--dst-prefix=.' will behave weirdly, replacing leading `/`
> by `.` (seems wrong)
> diff --git .Users/timothee/temp/ripgrep/help0.txt b/help1.txt

This is because the default prefixes are a/ and b/, respectively, and
the option allows you to entirely replace them. E.g. imagine needing
"../some-relative-path/"

> NOTE: I'm invoking the `git diff` command via a more complicated case
> (with multiple arguments including git diff flags and git diff files),
> so it's awkward for me to parse which arguments correspond to a file
> vs a flag (ie prevents easily converting input file arguments to
> absolute paths), but `git` could do it easily via a flag, eg
> `--show-abs-path`

  reply	other threads:[~2018-08-23  9:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-23  9:15 [feature] how to output absolute paths in git diff? => --show-abs-path Timothee Cour
2018-08-23  9:42 ` Ævar Arnfjörð Bjarmason [this message]
2018-08-23 11:24   ` Timothee Cour

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CACBZZX6F1ez-yfnc3asPXBkBd9VKCjS7paN5ZsWVnpn=QUyGew@mail.gmail.com' \
    --to=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=timothee.cour2@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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).